당신은 돌아 오는을 통해 그것을 아직도 모든 구성 요소에 대한 업데이트를 방지 할 수 있습니다합니다. 예, 현재 구성 요소를 업데이트해야하는지 여부를 결정할 수 있습니다. 다음은 샘플 코드입니다
반응-REDUX 라이브러리와 같은 일이와 전자의 경우 유사한 여러 다른 구성 요소가 그래서 상상
const mapStateToProps = (state) => {
return {
todos: getVisibleTodos(
state.todos,
state.visibilityFilter
)
};
};
const mapDispatchToProps = (dispatch) => {
return {
onTodoClick: (id) => {
dispatch({
type: 'TOGGLE_TODO',
id
});
}
};
};
const { connect } = ReactRedux;
const VisibleTodoList = connect(
mapStateToProps,
mapDispatchToProps
)(TodoList);
으로 수행 this.forceUpdate()
및 this.unsubscribe()
호출됩니다
class VisibleTodos extends Component{
componentDidMount(){
this.unsubscribe = store.subscribe(() => {
this.forceUpdate();
});
}
componentWillUnmount() {
this.unsubscribe();
}
render(){
const state = store.getState();
return(
<TodoList
todos = {getVisibleTodos(
state.todos,
state.visibilityFilter
)}
onTodoClick = {id => {
store.dispatch({
type: 'TOGGLE_TODO',
id
})
}}
>
</TodoList>
)
}
}
것 중복 될 수있다. 따라서 수동 작업에서 우리를 구할 수 있습니다.
react-redux를 사용하면 'connect' 기능을 사용하여 구성 요소를 스토어에 연결할 수 있습니다. 'connect'가 없으면 수동으로해야합니다. 그리고 일반적으로 모든 도서관의 목적은 수작업 작업을 줄이는 것입니다. –
Redux에서 생성 한 모든 가입은 해당 상태 슬라이스에서 작업해야하는지 여부와 상관없이 모든 상태 변경시 호출됩니다. 'react-redux'는 우리가 특정 컴포넌트를 구독해야하는 상점의 특정 부분을 지정할 수있게하므로 우리가 원하는 변경에만 "가입"합니다. – lux