{
type: "EXAMPLE_TYPE",
payload: amount
}
const withdrawMoney = (param) => {
return {
type: WITHDRAW_MONEY,
payload: amount
}
}
state
export sampleReducer (state=initialState, action) {
switch (action.type) {
case WITHDRAW_MONEY:
return {
...state,
ammount: payload
}
default:
return state;
}
}
어플리케이션의 모든 state는 단일 store에서 관리
state의 변경은 반드시 action을 통해서
(변경은 순수함수를 통해서만)
Reducer는 순수함수로 정의
인수변경 x, API 호출 x, 네트워크 요청 x, 순수함수가 아닌 함수(Date.now(), Math.random)의 호출 x
Failed to launch the app on simulator, An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405): Unable to lookup in current state: Shutdown
import React from 'react';
import { AppRegistry } from 'react-native';
import App from './app/index';
import { name as appName } from './app.json';
import { createStore, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import promiseMiddleware from 'redux-promise';
import reducers from './app/store/reducers';
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPONSE__ || compose
const createStoreWithMiddleware = createStore(reducers, composeEnhancers(
applyMiddleware(promiseMiddleware)
))
const appRedux = () => (
<Provider store={createStoreWithMiddleware}>
<App />
</Provider>
)
AppRegistry.registerComponent(appName, () => appRedux);
yarn/npx eslint --init
How would you like to use EsLint ?
- To check syntax, find problems, and enforce code style
What type of modules does your project use ?(Use arrow keys)
- JavaScript modules (import/export)
Which framework does your project use ? (Use arrow keys)
- React
Does your project use TypeScript ? (Y/N)
- N
Where does your code run ? (Press <space> to select, <a> to toggle all, <i> to invert selection)
- Node
How would you like to define a style for your project ? (Use arrow keys)
- Answer questions about your style
What format do you want your config file to be in ? (Use arrow keys)
- JavaScript
What style of indentation do you use ? (Use arrow keys)
- Spaces
What quotes do you use for strings ? (Use arrow keys)
- Single
What line endings do you use ? (Use arrow keys)
- Unix
Do you require semicolons? (Y/n)
- y
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ." // 추가하기
},
yarn add --save-dev prettier eslint-plugin-prettier
/* eslint-disable no-undef */
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 13,
sourceType: 'module',
},
plugins: ['react', 'react-hooks', 'prettier'],
rules: {
'prettier/prettier': ['error', { singleQuote: true, parser: 'flow' }], // 싱글 따옴표 사용 (공식문서참고) https://github.com/prettier/eslint-plugin-prettier#options
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single', { avoidEscape: true }],
},
};
module.exports = {
jsxBracketSameLine: true,
trailingComma: 'all',
arrowParens: "avoid",
singleQuote: true,
semi: true,
bracketSpacing: true,
useTabs: false,
jsxSingleQuote: false,
quoteProp: "as-needed",
tabWidth: 2,
printWidth: 80,
endOfLine: "auto"
};
yarn run lint // 실행
yarn eslint . --fix // 모든 에러 수정