loading json data from local file into React JS

前端 未结 8 1739
无人及你
无人及你 2020-11-30 00:33

I have a React component and I want to load in my JSON data from a file. The console log currently doesn\'t work, even though I\'m creating the variable data

8条回答
  •  爱一瞬间的悲伤
    2020-11-30 00:51

    I was trying to do the same thing and this is what worked for me (ES6/ES2015):

    import myData from './data.json';
    

    I got the solution from this answer on a react-native thread asking the same thing: https://stackoverflow.com/a/37781882/176002

提交回复
热议问题