Closed someyoungideas closed 6 years ago
@someyoungideas thanks for the input, I may be wrong since I'm still mastering (p)react myself but I don't think this is needed. In (p)react, state is passed top down, so change at the parent level will cause an update to the children level automatically. Are you seeing instances of this not happening when you run the app - if so, can you create an issue detailing this so we can discuss how best to resolve?
In (p)react, you don't need to call all lifecycle hooks unless you need to do something within the given lifecycle based on its intended purpose. From my understanding, componentWillReceiveProps
is to allow additional processing before props are updated: https://developmentarc.gitbooks.io/react-indepth/content/life_cycle/update/component_will_receive_props.html. It's intent is not to actually write the logic for manually updating the props...that is handled inherently within the preact paradigm.
@jkwening I made that change real quick during a break. Thanks for catching that. I am planning to debug it again this evening and see if what you are mentioning works as expected. I was having issues with it last night, but they may have more to do with UX then actual functionality. I will keep you updated.
@someyoungideas thanks for confirming. FYI - you might find the following tool useful in debugging: https://github.com/facebook/react-devtools It allows you to inspect in the viewpoint of React hierarchy.
@jkwening it looks like everything is working as it should without the componentwillreceiveprops
. It seems I went down that path due to some UX questions I may have that I will create an Issue for.
Here is the issue I created #302.
Adding
componentwillreceiveprops
toSearch
component so that whennavigator.geolocation.getCurrentPosition
returns it updates the props of theSearch
component properly.I am up for discussion on this being new to Preact and React. I did a little research to find out how to update props from other components and was led to this method. I wasn't sure if setting the
props
like I did is the best manner for things.