Parent Child relationship
"Now after this, the next step is communicating with the parent component. Currently, there is no way that our child component can communicate with props. We want to communicate with the parent component as we want to send the selected books by the user to the parent component. The easiest way for a child to communicate with the parent is via props." Mike explained.
"But props are generally the attributes or properties that are sent to a child, right? How can a child communicate with the parent using them?" Shawn asked.
"Remember the {}
syntax. We can pass any valid expression as prop. We can pass a function callback as prop to a child component. A child can call it to update the state of the parent. Let's update our BookStore
component now." Mike explained.
// src/BookStore.js …… // Updating BookStore component updateFormData(formData) { console.log(formData); }, render() { switch (this.state.currentStep) { case 1: return <BookList...