Since React Native 0.4.3 you can read your local JSON file like this:
const customData = require('./customData.json');
and then access customData like a normal JS object.
----
import sample from '../dbstore/sample1.json'
const customData = require('./customData.json');
import sample from '../dbstore/sample1.json'
const reducer = (state = [], action) => {
switch (action.type) {
case 'split_string':
return action.payload.split('')
case 'add_character':
return [...state, action.payload]
default:
return state;
}
}
const store = Redux.createStore(reducer)
store.getState()
const action1 = {
type: 'split_string',
payload: 'abcd'
}
store.dispatch(action1)
store.getState()
const action2 = {
type: 'add_character',
payload: 'e'
}
store.dispatch(action2)
store.getState()
Output:
[]
{"type":"split_string","payload":"abcd"}
["a","b","c","d"]
{"type":"add_character","payload":"e"}
["a","b","c","d","e"]
react-native init AwesomeAppAppRegistry.registerComponent('Bananas', () => Bananas);AppRegistry.registerComponent('AwesomeApp', () => Bananas);react-native start (i.e. React Native Packager) server running either on another terminal or another tab of TMUX (if you are using TMUX).react-native run-ios for instance, it will establish a new packager server that registered for that specific application.ps aux | grep react-native
kill command (e.g. kill -9 [PID]). You should find the launchPackager.command app in macOS, not sure about the other operating systems.run-ios (or android) again. You should be able to see the new path after running the new packager server, e.g.:Looking for JS files in
/Users/afshin/Desktop/awesome-app