re: How to pass state between components in reactjs VIEW POST


Hello Zeyad,

thanks for this state tutorial!

I was asking myself several questions while reading it though. I hope you can enlighten me :)

  • Why do you keep the book ID in the <Book> component state ? Wouldn't it be prettier to pass the prop when you call this.props.handleCounter in updateLibraryCount? To me, the ID should not be modified, so we don't have to put it in the state.

  • Is there any particular reason why you don't pass a function as the first argument of this?

    this.setState({status: !this.state.status}, this.updateLibraryCount);

Thanks again!

See you :)


Thanks Thomas, to your first question, you're right it'll be prettier, you're welcome to contribute and update this on GitHub repo.
To your second question, from Reactjs documentation

"The second parameter to setState() is an optional callback function that will be executed once setState is completed and the component is re-rendered."

and this what i want.

code of conduct - report abuse