01-08-2018 08:50
01-08-2018 08:50
I am attempting to use the sample code given for the button settings in the documentation.
In Setttings - index.jsx I have the import statement for settingsStrorage and the code for the button:
<Button
list
label="Clear All Settings"
onClick={() => this.props.settingsStorage.clear()}
/>
However - when I execute I get in the consolelog TypeError: undefined is not an object (evaluating '_this.props')
I am able to use settingsStorage.clear() in the companion index.js.
I am sure I am missing something obvious but it is Monday...
Best Answer01-09-2018 11:10 - edited 01-10-2018 12:05
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
01-09-2018 11:10 - edited 01-10-2018 12:05
You shouldn't need to import anything, but props needs to be in the function signature.
Try something like this:
function mySettings(props) {
return (
<Page>
<Section
title={<Text bold align="center">Settings</Text>}>
<Button
list
label="Clear All Settings"
onClick={() => props.settingsStorage.clear()}
/>
</Section>
</Page>
);
}
registerSettingsPage(mySettings);
[EDITED]
Best Answer01-09-2018 12:41
01-09-2018 12:41
I reduced my code to what you have and am still seeing the same issue.
Best Answer01-09-2018 12:47
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
01-09-2018 12:47
It looks like you're mixing the Settings API (jsx) with the Companion API (js).
Remove the first 2 import lines, and confirm that this file is settings/index.jsx
Best Answer01-10-2018 06:37
01-10-2018 06:37
I have confirmed that I am working within the index.jsx file. Taking out the two import lines did not help. I am still getting the same TypeError:
I also started a new settings project and put a simple textInput in with the above code and got the same error in there as well.
Best Answer01-10-2018 11:50
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
01-10-2018 11:50
In settings/index.jsx, this works for me:
<Button
label="Create/Update"
onClick={() => {
props.settingsStorage.setItem('createAccount', 'true');
}}
/>No 'import' statements or 'this' are required (or allowed).
Best Answer