Javascript 如何使用Ignite Bowser 2样板在React Native中点击/使用post并获取api。(Mobx状态列表,键入脚本)

Javascript 如何使用Ignite Bowser 2样板在React Native中点击/使用post并获取api。(Mobx状态列表,键入脚本),javascript,typescript,react-native,redux,mobx-state-tree,Javascript,Typescript,React Native,Redux,Mobx State Tree,我是新来的反应本机,请提供一些Github链接或您自己的代码作为参考。把我当作RN的初学者。 我发现对RN、Mobx状态树、Ignite和所有的开放性支持都非常少,所以不仅仅是发布和获取API参考,如果您发现与上述主题相关的任何有用信息,请随时分享 提前感谢。Mobx状态树,使用Ignite Bowler,您将拥有api.ts文件,可以在其中指定api调用 async getUser(userToken: string): Promise<Types.GetUserResult>

我是新来的反应本机,请提供一些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" }
}
}
异步getUser(userToken:string):承诺{ //进行api调用 const response:apisponse=wait this.apisoup.post(`api/v1/sales/login?authCode=${userToken}`) 如果(!response.ok){ 常量问题=GetGeneralApipProblem(响应) 如果(问题)返回问题 } //将数据转换为我们期望的格式 试一试{ 试一试{ const rawUser=response.data console.log('rawUser'+rawUser) const user:UserSnapshot=convertRawUserToUserStore(rawUser) 返回{kind:“ok”,user} console.log({user}) }捕获(e){ __DEV__&&console.tron.log(e.message) 返回{kind:“坏数据”} } }抓住{ 返回{kind:“坏数据”} } } 考虑一下,我们将从这个API调用中获取用户数据, 您可以注意到,有一个属于用户模型的UserSnapshot,Snapshot会自动保存数据,您不需要Aysnc存储来保存或检索数据