是React-redux的新成员。我正在尝试从组件A调用具有Redux对象的组件B。
我遇到编译时错误,并要求我传递mapStateToProps和mapDispatchToProps中存在的所有属性。
如果我必须调用ComponentB,是否需要传递mapStateToProps和mapDispatchToProps中存在的所有属性?
谢谢
请在下面找到示例代码。
interface ComponentBProps {
name : string;
}
interface ComponentBState {
name : string;
}
const mapStateToProps = (state: LibraryState) => ({
grade : state.LIbrary.grade,
section :state.LIbrary.section,
})
const mapDispatchToProps = (dispatch: Dispatch) => ({
class : (grade : number) => gradeActions.UpdateGrade(grade)(dispatch);
});
type CombinedProps = ReturnType<typeof mapDispatchToProps> & ReturnType<typeof mapStateToProps> & ComponentBProps;
export class ComponentB extends React.Component<CombinedProps , ComponentBState> {
constructor(props: DerivedProps) {
super(props);
this.state = { name : props.name };
}
//.....................
}
//Component A
//In component A render, I am trying make a call to componentB like this.
<ComponentB name={this.props.name} />