I want to update the Diagram component if I click on the Button.
I have the following structure:
+------+
-Layout|--\
-/+------+ |
-/ \
+-----/---+ +----|----+
| Sidebar | | Content |
+--|------+ +----|----+
/ \
+---|---+ +---|----+
|Button | |Diagram |
+-------+ +--------+
If I press the Button, the Diagram should update. My only idea how I can do this is the following:
- I define a
changeDiagram()function in theLayoutcomponent.- the changeDiagram function changes the variable named
typeto the value'barChart'
- the changeDiagram function changes the variable named
- I pass the
changeDiagramas a parameter to sidebar. If i click on the button the changeDiagram function gets excecuted. - I pass the
typevariable that is in the Layout component as a parameter to theContentcomponent. - The Content component renders the new Diagram
The problem is that I don't want to define a function that is only responsible for the Diagram inside the Layout Component. Also every Component between Layout and Diagram gets rendered, which is not necessary.
How to solve this problem? I heard of react-redux. Do I have to use this or are there other solutions?