Message from JavaScript discussions

March 2019

— Yep


I went through the life cycle methods of the react components. I read about the method getDerivedStateFromProps which is to be used to update the props of the child method whenever the parent method updates it's state. (as far as I read, please correct if I am wrong). I made a component Login which calls another component called Form, I am passing the handler methods (of inputs) as objects to the child form and handling the change. whenever my inputs are updated, I am only changing the state of the parent component Login and the props in the component Form are getting updated automatically. I am not using any life cycle method to update or check the change in state of the parent component. Then how are the props in the child component getting updated ??

— You misread, that lifecycle is to update the state of the component depending on its props.
If you’re passing the handler methods of the Login component to the Form component you’re making a controlled Form component.
This methods are executed by Form, yes. But they modify the state of Login. So, when you update the state it will re-render your Login component. Then it will call the re-render of Form component.

Message permanent page

— That lifecycle is when you have some state depending on the props you received. It can be painful to update the state of the component when the props update, and maintain them in sync, so they introduced this lifecycle.

In the example they mentioned children component because you can have a component that receives children and for some reason you want that children in the state.

Remember that if you compose something like this <Parent><Child/></Parent>

Parent will receive <Child/> in the children prop accesible as this.prop.children

Message permanent page

— Thanks for the help, yep you are true I got confused a bit 😅

— JavaScript logical programs list please or tell me any useful coding website

— Read the pinned message

— Ok

— Tq

— How can I set a custom css property with js? (I have already searched but I have not found anything)

— I guess there are many ways to perform this. One of the way can be document.getElementById("id") = property

Message permanent page

— I got gud now