Created
November 2, 2017 00:34
-
-
Save TechNinjaWeb/f8dcb20a4c21c8fd7c57ebd0f0271bb8 to your computer and use it in GitHub Desktop.
Basic starter template for Redux with React-Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AppRegistry, Text } from 'react-native' | |
import { createStore } from 'redux' | |
// Define action types | |
const types = { | |
INCREMENT: 'INCREMENT', | |
} | |
// Define a reducer | |
const reducer = (state, action) => { | |
if (action.type === types.INCREMENT) { | |
return {count: state.count + 1} | |
} | |
return state | |
} | |
// Define the initial state of our store | |
const initialState = {count: 0} | |
// Create a store, passing our reducer function and our initial state | |
const store = createStore(reducer, initialState) | |
/// We're done! Redux is all set up. Here's how we can use it: | |
// Now we can dispatch actions, which are understood by our store/reducer | |
store.dispatch({type: types.INCREMENT}) | |
store.dispatch({type: types.INCREMENT}) | |
store.dispatch({type: types.INCREMENT}) | |
// Calling `store.getState()` returns our state object | |
const App = () => ( | |
<Text style={{fontSize: 100}}> | |
{store.getState().count} | |
</Text> | |
) | |
AppRegistry.registerComponent('App', () => App) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment