How to pass state value from one component to another in Reactjs?

Posted by Jennifer | Updated on

Want to pass state value from one component to another in Reactjs? If you have to pass state from Dashboard to Sidebar, you have to render Sidebar from Dashboard’s render function. Here, you can pass the state of Dashboard to Sidebar.

If you want the changes made on props (data1) passed to Sidebar be received by Dashboard, you need to lift the state up. i.e, You have to pass a function reference from Dashboard to Sidebar. In Sidebar, you have to invoke it whenever you want the data1 to be passed back to Dashboard. Code snippet.

Reference Doc: https://facebook.github.io/react/docs/lifting-state-up.html


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers