如何正确使用AsyncStorage(react-native)?

时间:2016-02-10 06:40:59

标签: javascript reactjs react-native

例如如何正确存储用户,例如[{username:'username',name:'name',surname:'surname'},{username:'username1',name:'name1',surname:'surname1' }]?只是喜欢这个代码吗?

     return AsyncStorage.getItem('users')
            .then(req => JSON.parse(req))
            .then(json => {
             json.push(newUser);
               return AsyncStorage.setItem('users', JSON.stringify(json))
                    .then(json => console.log('success!'))
                    .catch(error => console.log(error));
            })
            .catch(error => console.log(error));

0 个答案:

没有答案