Last active
August 26, 2017 14:31
-
-
Save jonatassaraiva/c1278c1d1c4eb5472cf0b667ea034394 to your computer and use it in GitHub Desktop.
Start project 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
Files: | |
* .gitignore | |
* index.android.js | |
* index.ios.js | |
* package.json | |
* settings.json | |
* src/actions/application/index.js | |
* src/app.js | |
* src/components/info.js | |
* src/reducers/application/info.js | |
* src/reducers/root.js | |
* src/store/index.js | |
* .eslintrc |
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
{ | |
"extends" : "airbnb", | |
"rules" : { | |
"react/jsx-filename-extension": ["error", { "extensions": [".js", ".jsx"] }], | |
"comma-dangle":"off" | |
} | |
} |
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
#vscode | |
.vscode | |
jsconfig.json |
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 } from 'react-native'; | |
import App from './src/app'; | |
AppRegistry.registerComponent('manager', () => App); |
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 } from 'react-native'; | |
import App from './src/app'; | |
AppRegistry.registerComponent('manager', () => App); |
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
// Add | |
{ | |
"scripts": { | |
"openDebug": "open 'rndebugger://set-debugger-loc?host=localhost&port=8081'", | |
"postinstall": "rndebugger-open" | |
}, | |
} |
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
// File VSCODE .vscode/settings | |
{ | |
"files.associations": { | |
"**/src/actions/**/.js": "javascript", | |
"**/src/reducers/**/.js": "javascript", | |
"**/src/store/**/.js": "javascript", | |
"**/src/**/*.js": "javascriptreact" | |
} | |
} |
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 packageInfo from '../../../package.json'; | |
export const applicationTypes = { | |
LOAD_PACKGE_INFO: 'LOAD_PACKGE_INFO' | |
}; | |
export const loadPacageInfo = () => (dispatch) => { | |
return dispatch(load(packageInfo)); | |
}; | |
const load = payload => ({ | |
type: applicationTypes.LOAD_PACKGE_INFO, | |
payload | |
}); |
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 React, { Component } from 'react'; | |
import { View } from 'react-native'; | |
import { Provider } from 'react-redux'; | |
import store from './store'; | |
import Info from './components/info'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
} | |
componentWillMount() { | |
this.store = store.configure(); | |
} | |
render() { | |
return ( | |
<Provider store={this.store}> | |
<View style={{ flex: 1 }}> | |
<Info /> | |
</View> | |
</Provider> | |
); | |
} | |
} | |
export default App; |
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 React, { Component } from 'react'; | |
import { View, Text } from 'react-native'; | |
import { connect } from 'react-redux'; | |
import { loadPacageInfo } from '../actions/application'; | |
class Info extends Component { | |
constructor(props) { | |
super(props); | |
} | |
componentWillMount() { | |
this.props.loadPacageInfo(); | |
} | |
render() { | |
const { name, version } = this.props; | |
return ( | |
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | |
<Text> | |
{name} | |
</Text> | |
<Text> | |
{version} | |
</Text> | |
</View> | |
); | |
} | |
} | |
const mapStateToProps = state => { | |
const { name, version } = state.application; | |
return { name, version }; | |
}; | |
export default connect(mapStateToProps, { loadPacageInfo })(Info); |
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 { applicationTypes } from '../../actions/application'; | |
const initialState = { | |
version: '', | |
name: '' | |
}; | |
export default function info(state = initialState, action) { | |
switch (action.type) { | |
case applicationTypes.LOAD_PACKGE_INFO: { | |
const { version, name } = action.payload; | |
return { ...state, version, name }; | |
} | |
default: | |
return state; | |
} | |
} |
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 { combineReducers } from 'redux'; | |
import info from './application/info'; | |
export default combineReducers({ | |
application: info | |
}); |
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 { createStore, applyMiddleware, compose } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import rootReducer from '../reducers/root'; | |
const store = { | |
configure: (initialState) => { | |
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? | |
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ | |
shouldHotReload: false | |
}) : compose; | |
const enhancer = composeEnhancers( | |
applyMiddleware(thunk) | |
); | |
return createStore(rootReducer, enhancer); | |
} | |
}; | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NPM INSTALL REACT NATIVE DEBUG
brew update && brew cask install react-native-debugger
npm install --save-dev react-native-debugger-open
open 'rndebugger://set-debugger-loc?host=localhost&port=8081'
NPM INSTALL ESLINT
npm install --save-dev eslint-config-airbnb eslint eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react
NPM INSTALL REDUX
npm install --save redux react-redux redux-thunk
NPM INSTALL
npm install