Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating the breakpointCols object doesn't update the app until i manually resize it #20

Open
hardtekpt opened this issue Aug 31, 2018 · 3 comments
Labels
faq Add to readme

Comments

@hardtekpt
Copy link

hardtekpt commented Aug 31, 2018

Having a sidebar in my app I would like the columns to update with the sidebar being open or not. To do this i updated the breakpointCols object with new values but it doesn't change the app until i manually change the window size. Not sure if I'm being clear or not, but hope the images bellow help.

captura de ecra 2018-08-31 as 15 43 14

As you can see here the columns are displaying correctly

captura de ecra 2018-08-31 as 15 46 39

However when I open the sidebar the breakpoint values get updated but not the app. In this case there should be only 2 columns

captura de ecra 2018-08-31 as 15 49 04

The desired behaviour only occurs when i resize the windows itself


I would really appreciate if someone could help me fix this

EDIT:

here's the code: (For whatever reason I can't format it here)
I swapped the code for an image as I could not format it right

captura de ecra 2018-08-31 as 22 10 44

@paulcollett
Copy link
Owner

it's possible to trigger a refresh manually, by using a ref on the component and calling the reCalculate function.

Ideally when changing you specify new breakpoint col values we do update the layout accordingly. I'm going to look into making sure this piece works

@hardtekpt
Copy link
Author

Thanks for helping!!

Can you explain this manual refresh pls. Maybe with an example. Also if you need any other parts of the code I can provide them

Copy link

@paulcollett is referring to the reCalculateColumnCount method defined here:

reCalculateColumnCount() {

Implementing the above solution would look something like that:

class MyComponent extends React.Component {
  constructor() {
    super();
    this.masonryRef = React.createRef();
  }

  componentDidUpdate(prevProps, prevState, snapshot) {
    const masonry = this.masonryRef.current;
    masonry && masonry.reCalculateColumnCount();
  }

  render() {
    const { breakpointCols } = this.props;
    return <Masonry ref={ this.masonryRef } breakpointCols={ breakpointCols } />
  }
}

@paulcollett paulcollett added the faq Add to readme label Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq Add to readme
Projects
None yet
Development

No branches or pull requests

3 participants