My react app has a toggle button called Technical. If it is toggled on, we display , a custom component that offers a collection of highly technical options for the user. It has a lot of state. I am having this problem: when the user toggles the Technical button off, the stored state vanishes, and when the button is toggled back on, we are returned to the default state.
How can I preserve that state while making the FilterGroup (and the screen real estate it takes up) temporarily vanish?
Already tried:
- Wrapping this entire item in <> </>
- Wrapping FilterGroup in <> </>
Here’s the relevant code:
{technical ? <FilterGroup ref={(fg) => theFilterGroup = fg} /> : null}
2
Answers
Thank you, Unmitigated, for half the answer. Here's what else I had to do. This is an excerpt from my FilterGroup render function, as corrected.
By way of explanation, r.from and r.to (fields of each Range object in the range array) are strings which are field names in this.state. r.min and r.max are numbers. Previously the defaultValue line read:
and this default value was being reimposed every time the FilterGroup reappeared after having disappeared.
You can pass a prop to
FilterGroup
to indicate whether or not to show it.