Giter Site home page Giter Site logo

Comments (3)

monder avatar monder commented on August 15, 2024

It should work.
Where exactly is componentWillReceiveProps is triggered? In ItemsList component?
If props change it should fetch the new url.
The example does implement similar thing, no?

from react-resolver.

benbonnet avatar benbonnet commented on August 15, 2024

Hmm… Im still not that convinced yet :/

Having this :

@resolve("item", function(props){
  var url           = "/item/" + props.params.slug
  return axios.get(url).then((response) => response.data
})
export default class ItemsList extends Component {
  render(){
    const { item } = this.props;
    return(
      <ChildComponent item={item}>
    )
  }
})

I think I had the same problem on the initial question.
As you said it was not explicit enough, hope it is here

If I was on /item/xxx and that I go to /item/zzz, @resolve is triggered, I do get a new render for the component, but the child component will not receive the new prop — which feels buggy. The componentWillReceiveProps of the child is not triggered. So it differs from the example you're pointing out as i'm using (maybe by mistake) a child component

I first though it was simply the fact of using a const on the proptype before returning the render, but i might just have been wrong thinking that

from react-resolver.

TriPSs avatar TriPSs commented on August 15, 2024

@bbnnt When the url changes you should check that in the componentWillReceiveProps and then refetch the data like this:

@resolve('company', (props) => {
  const { companySlug } = props.params

  return props.getCompany(companySlug).then(payload => payload)
})
export class Company extends React.Component {

  componentWillReceiveProps(nextProps) {
    const { params: { companySlug }, getCompany }     = this.props
    const { params: { companySlug: newCompanySlug } } = nextProps

    if (newCompanySlug !== companySlug)
      getCompany(newCompanySlug)
  }
}

componentWillReceiveProps Got called because the route changes so the param attribute is being updated.

In my example getCompany is a function the container connects to the component.

from react-resolver.

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.