Save boolean data by use AsyncStorage in redux
up vote
0
down vote
favorite
I want to set state "true" or "false" when click a button, and save it by using AsyncStorage in react native with redux.
Did I do correctly ? Please help me fix it.
import { AsyncStorage } from "react-native";
import {
START_TOOLTIP_BUDGET,
STOP_TOOLTIP_BUDGET
} from "../actions/ActionTypes";
const INIT_STATE = true;
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return INIT_STATE;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return INIT_STATE;
default:
return state;
}
};
javascript java android ios react-native
add a comment |
up vote
0
down vote
favorite
I want to set state "true" or "false" when click a button, and save it by using AsyncStorage in react native with redux.
Did I do correctly ? Please help me fix it.
import { AsyncStorage } from "react-native";
import {
START_TOOLTIP_BUDGET,
STOP_TOOLTIP_BUDGET
} from "../actions/ActionTypes";
const INIT_STATE = true;
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return INIT_STATE;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return INIT_STATE;
default:
return state;
}
};
javascript java android ios react-native
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to set state "true" or "false" when click a button, and save it by using AsyncStorage in react native with redux.
Did I do correctly ? Please help me fix it.
import { AsyncStorage } from "react-native";
import {
START_TOOLTIP_BUDGET,
STOP_TOOLTIP_BUDGET
} from "../actions/ActionTypes";
const INIT_STATE = true;
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return INIT_STATE;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return INIT_STATE;
default:
return state;
}
};
javascript java android ios react-native
I want to set state "true" or "false" when click a button, and save it by using AsyncStorage in react native with redux.
Did I do correctly ? Please help me fix it.
import { AsyncStorage } from "react-native";
import {
START_TOOLTIP_BUDGET,
STOP_TOOLTIP_BUDGET
} from "../actions/ActionTypes";
const INIT_STATE = true;
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return INIT_STATE;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return INIT_STATE;
default:
return state;
}
};
javascript java android ios react-native
javascript java android ios react-native
edited Nov 11 at 13:54
asked Nov 11 at 10:05
Duc Huy Nguyen
14
14
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Yes you can do it correctly but if yo return INIT_STATE true or false, you can get current data for your current class. Otherwise you return true every time.
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return true;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return false;
default:
return state;
}
};
And than get it from class that click the button. And also you can get the AsyncStorage item;
AsyncStorage.getItem("INIT_STATE")
.then(req => JSON.parse(req))
.then(data => {
if (data !== null) {
console.log(data); // true or false
}
}).done();
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Yes you can do it correctly but if yo return INIT_STATE true or false, you can get current data for your current class. Otherwise you return true every time.
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return true;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return false;
default:
return state;
}
};
And than get it from class that click the button. And also you can get the AsyncStorage item;
AsyncStorage.getItem("INIT_STATE")
.then(req => JSON.parse(req))
.then(data => {
if (data !== null) {
console.log(data); // true or false
}
}).done();
add a comment |
up vote
0
down vote
Yes you can do it correctly but if yo return INIT_STATE true or false, you can get current data for your current class. Otherwise you return true every time.
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return true;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return false;
default:
return state;
}
};
And than get it from class that click the button. And also you can get the AsyncStorage item;
AsyncStorage.getItem("INIT_STATE")
.then(req => JSON.parse(req))
.then(data => {
if (data !== null) {
console.log(data); // true or false
}
}).done();
add a comment |
up vote
0
down vote
up vote
0
down vote
Yes you can do it correctly but if yo return INIT_STATE true or false, you can get current data for your current class. Otherwise you return true every time.
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return true;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return false;
default:
return state;
}
};
And than get it from class that click the button. And also you can get the AsyncStorage item;
AsyncStorage.getItem("INIT_STATE")
.then(req => JSON.parse(req))
.then(data => {
if (data !== null) {
console.log(data); // true or false
}
}).done();
Yes you can do it correctly but if yo return INIT_STATE true or false, you can get current data for your current class. Otherwise you return true every time.
export default (state = INIT_STATE, action) => {
switch (action.type) {
case START_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(true));
return true;
case STOP_TOOLTIP_BUDGET:
AsyncStorage.setItem("INIT_STATE", JSON.stringify(false));
return false;
default:
return state;
}
};
And than get it from class that click the button. And also you can get the AsyncStorage item;
AsyncStorage.getItem("INIT_STATE")
.then(req => JSON.parse(req))
.then(data => {
if (data !== null) {
console.log(data); // true or false
}
}).done();
answered Nov 12 at 14:23
Yasin Ugurlu
15217
15217
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247627%2fsave-boolean-data-by-use-asyncstorage-in-redux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown