javascript - 如何使用 Ignite Bowser 2 Boilerplate 在 React Native 中点击/使用帖子并获取 api。(Mobx 状态树,输入脚本)
问题描述
我是 React Native 的新手,请提供一些 Github 链接或您自己的代码以供参考。将我视为 RN 的初学者。
我发现对 RN、Mobx 状态树、Ignite 等的开放支持非常少,所以不仅仅是发布和获取 API 参考,如果您发现与上述主题相关的任何有用信息,请随时分享。
提前致谢。
解决方案
Mobx 状态树,使用 Ignite Bowler,您将拥有 api.ts 文件,您可以在其中指定 API 调用。
async getUser(userToken: string): Promise<Types.GetUserResult> {
// make the api call
const response: ApiResponse<any> = await this.apisauce.post(`api/v1/sales/login?authCode=${userToken}`)
if (!response.ok) {
const problem = getGeneralApiProblem(response)
if (problem) return problem
}
// transform the data into the format we are expecting
try {
try {
const rawUser = response.data
console.log('rawUser'+ rawUser)
const user: UserSnapshot = convertRawUserToUserStore(rawUser)
return { kind: "ok", user }
console.log({ user })
} catch (e) {
__DEV__ && console.tron.log(e.message)
return { kind: "bad-data" }
}
} catch {
return { kind: "bad-data" }
}
}
考虑一下,我们将从这个 API 调用中获取用户数据,您可以注意到有属于 User Model 的 UserSnapshot,Snapshot 会自动保存数据,您不需要 Aysnc 存储来保存或检索数据。
推荐阅读
- python - 拆分 url 并在列中从该 URl 获取值
- python - 使用 TimeDistributed Conv2D 层包装器
- javascript - MongoDB > 我可以在查询中使用实例数据 upsertMany
- python - 实时分类图像中的新对象
- java - 无法将未绑定命名空间的 xml 转换为 java 对象,我也无法对 XML 进行任何更改
- cordova - 在 Ionic 中将图像保存到图库时出错?
- java - 为什么 JPA/Hibernate 设计了一种强制重新定义事务边界的方法,即使对于一个插入/更新数据库语句?
- google-apps-script - 结合 autoResizeRows 并将空行设置为大小为 1
- python - 传递一个列表或可变数量的参数作为方法参数
- c++11 - 如何确定 X 是否可以表示为任何 Y 不同正整数的总和?