나만알아보는
dispatch(action()) -> reducer(스테이트값변경) -> useSelector(변화감지) -> 새로운뷰
<Provider stroe={store}>
<App>
</Provider>
위와 같이 store와 컴포넌트를 연결 변화를 감지하고 새로운뷰를 보여줄 수 있게 연결을 해준다.
리덕스 connet
hook이 아닌 사용법 알아둘 필요가 있다.
usedispatch => connet(mapStateToProps, null)()
useSelector => connet(null, mapDispatchToProps)()
비동기는 redux-thunk를 사용한다.
// src/services/note.js
import aixos from 'axios';
const baseUrl = www.exmaplenotes.com
const getAll = async () => {
return await axios.get(baseUrl).data
export defalut { getAll }
// src/reducers/notereducer
export const initializeNotes = () => {
return async dispatch => {
const notes = await noteService.getAll()
dispatch({
type: 'INIT_NOTES',
data: notes,
})
}
}
export interface { ... }
Compiling vs Transpiling
https://stackoverflow.com/questions/44931479/compiling-vs-transpiling