How to fetch data from local JSON file on react native?

后端 未结 7 1576
执念已碎
执念已碎 2020-12-02 10:12

How can I store local files such as JSON and then fetch the data from controller?

相关标签:
7条回答
  • 2020-12-02 11:08

    For ES6/ES2015 you can import directly like:

    // example.json
    {
        "name": "testing"
    }
    
    
    // ES6/ES2015
    // app.js
    import * as data from './example.json';
    const word = data.name;
    console.log(word); // output 'testing'
    

    If you use typescript, you may declare json module like:

    // tying.d.ts
    declare module "*.json" {
        const value: any;
        export default value;
    }
    
    0 讨论(0)
提交回复
热议问题