Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggle default to true

ANSWERED

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

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
1 REPLY 1

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes