04-12-2020 23:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-12-2020 23:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Accepted Solutions
04-12-2020 23:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-12-2020 23:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

04-12-2020 23:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-12-2020 23:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

