paint-brush
Common pitfall in initialising state based on props in React JSby@atul04
33,788 reads
33,788 reads

Common pitfall in initialising state based on props in React JS

by Atul Kumar2mOctober 21st, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Recently I ran into this issue while working on <a href="https://hackernoon.com/tagged/react-js" target="_blank">React JS</a> project where I was passing a part of parent <a href="https://hackernoon.com/tagged/component" target="_blank">component</a> state to child component via props. Then I was using that prop to set the initial state of my child component (after doing some other calculations). So the problem was when the parent component re-renders on state change, the child component is not rendered with updated state value. For example —

Company Mentioned

Mention Thumbnail
featured image - Common pitfall in initialising state based on props in React JS
Atul Kumar HackerNoon profile picture
Atul Kumar

Atul Kumar

@atul04

L O A D I N G
. . . comments & more!

About Author

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite