04-12-2020 23:32
04-12-2020 23:32
Hi fellow developers,
I have the question if and how i should set a toggle default to true. I use this code
in my settings.jsx
<Toggle
settingsKey="myHRM"
// label="View my hear rate"
label={`View my heart rate.`}
onChange={(value) => console.log(value)}
/
....
Looking forward to read from you,
Robert
Answered! Go to the Best Answer.
04-12-2020 23:43
04-12-2020 23:43
Unfortunately, it seems to depend on where you want to set the default.
In index.js, I think it would be something like
settingsStorage.setItem('myHRM', true)
In index.jsx, I think it would be something like
props.settingsStorage.setItem('myHRM', 'true')
I actually tend to do it in both places, because you can never be sure which file will run first. That makes it tricky to ensure that you don't reset the setting back to default when it had a previous legitimate value — but that's another story.
04-12-2020 23:43
04-12-2020 23:43
Unfortunately, it seems to depend on where you want to set the default.
In index.js, I think it would be something like
settingsStorage.setItem('myHRM', true)
In index.jsx, I think it would be something like
props.settingsStorage.setItem('myHRM', 'true')
I actually tend to do it in both places, because you can never be sure which file will run first. That makes it tricky to ensure that you don't reset the setting back to default when it had a previous legitimate value — but that's another story.