I have two calendars, such as the Agenda, have an icon calendar button, when I click on it, it will be redirected to another calendar (Planning)
, these calendars are developed with react-big-calendar, I want when I navigate for example on the week of juin 17 - 23
of Agenda and I click on the icon calendar, it will be redirected to juin 17 - 23
of the Planning.
My code is : https://codesandbox.io/s/m7k904y3o8
I try to send the date with getWeek()
, but it doesn't work.
How can I fix it ?
You can add additional data to
this.props.history.push
which will then be available in thelocation
prop on yourPlanning
component. For example if you want to view the Week of the 20th December 1995:Two other solutions I would recommend are URL parameters and Query parameters.
You should use some state management lib
My first advice would be to use Redux since the library handles situations like this very well. You want to pass some data between unrelated components. Having a state object would serve you quite well here.
The second (easier/quicker) option is to add some state management to a parent component (this is called a container). You can pass some state to each of the children as well as a setter function that you can fire from the child.
Example of your App component as a container
Some things to note
autobind
decorator is to make this easier to write, you can bind your function in the constructor if you want insteadsetActiveDate
from the child (Agenda)Conclusion
This method will pollute your components much more than a redux implementation. But it is quicker than a full redux setup. Just try to remember the "Single responsibility principal".