Giter VIP home page Giter VIP logo

Comments (7)

kylealwyn avatar kylealwyn commented on July 2, 2024

you need to bind the function you pass into ref to this

ref={function(c) {this.masonry = c.masonry}.bind(this)}

from react-masonry-component.

afairbrother avatar afairbrother commented on July 2, 2024

Despite binding the function to this there is still an error in the console. Uncaught TypeError: Cannot read property 'masonry' of null

from react-masonry-component.

 avatar commented on July 2, 2024

I've relegated to doing something like:

<Masonry ref="masonry" ... />

And to reference in another method within the component:

componentWillReceiveProps() {
  this.refs.masonry.performLayout()
}

from react-masonry-component.

afairbrother avatar afairbrother commented on July 2, 2024

Ah, thanks @alwynsays, this worked for me

from react-masonry-component.

UgRoss avatar UgRoss commented on July 2, 2024

From React Docs:

Although string refs are not deprecated, they are considered legacy, and will likely be deprecated at some point in the future. Callback refs are preferred.

You can do it like this:

<Masonry ref={c => this.masonry = c} ... />

and

componentWillReceiveProps() {
  this.masonry.performLayout()
}

from react-masonry-component.

afram avatar afram commented on July 2, 2024

@ybv not sure why this isn't working for you. It's working fine for me and my code looks very similar to yours.

What versions of React/react-masonry-component/babel are you using?

from react-masonry-component.

afram avatar afram commented on July 2, 2024

I'm closing this issue. Please reopen if needed.

from react-masonry-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.