React native react native中不同用户类型的不同视图
目前,我正在使用expo做一个react native项目,我想在我的应用程序中创建2个用户类型(例如:学生和讲师)。保存用户类型的最佳方法是什么?要在react本机应用程序中管理状态,您需要谷歌搜索的内容有:react本机异步存储、react状态存储、redux、react挂钩、redux替代方案。这应该可以让您开始了。您可以将这些类型的信息保存在react native异步存储中。React native react native中不同用户类型的不同视图,react-native,expo,React Native,Expo,目前,我正在使用expo做一个react native项目,我想在我的应用程序中创建2个用户类型(例如:学生和讲师)。保存用户类型的最佳方法是什么?要在react本机应用程序中管理状态,您需要谷歌搜索的内容有:react本机异步存储、react状态存储、redux、react挂钩、redux替代方案。这应该可以让您开始了。您可以将这些类型的信息保存在react native异步存储中。假设对于学生,您可以保存1,对于讲师,您可以保存2。但请记住,异步存储总是将字符串作为输入,所以在保存或检索时不
假设对于学生,您可以保存1,对于讲师,您可以保存2。但请记住,异步存储总是将字符串作为输入,所以在保存或检索时不要忘记转换。基于此,您可以检查当前哪个用户正在访问应用程序,然后您只需渲染该视图 存储数据的示例代码:
storeData = async () => {
try {
await AsyncStorage.setItem('@storage_Key', 'stored value')
} catch (e) {
// saving error
}
}
getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
// value previously stored
}
} catch(e) {
// error reading value
}
}
tempUserType ===1 ? <code view for student> : <code view for lecturer>
读取数据:
storeData = async () => {
try {
await AsyncStorage.setItem('@storage_Key', 'stored value')
} catch (e) {
// saving error
}
}
getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
// value previously stored
}
} catch(e) {
// error reading value
}
}
tempUserType ===1 ? <code view for student> : <code view for lecturer>
最后,您可以进行条件视图渲染,如下所示:
storeData = async () => {
try {
await AsyncStorage.setItem('@storage_Key', 'stored value')
} catch (e) {
// saving error
}
}
getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
// value previously stored
}
} catch(e) {
// error reading value
}
}
tempUserType ===1 ? <code view for student> : <code view for lecturer>
tempUserType===1<学生代码视图>:<讲师代码视图>
在这里,您可以阅读更多内容:-
我希望这有助于。。。。。谢谢:)您可以通过更具体的方式改进此问题。广泛的、基于意见的问题很可能会被主持人关闭。提出一些方法。与其问什么是最好的,不如详细说明您对解决方案的期望,并询问建议的方法最有可能导致您期望的结果。