Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

脚手架之前用 redux 时候的一些问题。 #22

Open
cycallj opened this issue Jun 12, 2019 · 4 comments
Open

脚手架之前用 redux 时候的一些问题。 #22

cycallj opened this issue Jun 12, 2019 · 4 comments

Comments

@cycallj
Copy link

cycallj commented Jun 12, 2019

就是想请教一下,
您这个脚手架之前用 redux 做 state 管理的时候,
一旦我有个组件要用 store 的 state 或 action 的时候,我就要把相关的 state 和 action 引入、bindActionCreators,然后在 export 的时候 去connect 。例子:
`const mapStateToProps = state => ({
publicState: state.public
});

const mapDispatchToProps = dispatch => ({
publicActions: bindActionCreators(publicActions, dispatch)
});

export default connect(mapStateToProps, mapDispatchToProps)(Component);`

觉得很繁琐,有没有一个办法,在初始化页面的时候就全部声明好,存到一个静态的地方Global,然后用的时候只要用Global就可以了,的方法。
我按照上面试了下,发现能拿到,但是会使 react-router 失效。感觉进入了死胡同。

谢谢。

@aiyuekuang
Copy link
Owner

就是应为像你说的那样把redux整合到一个初始化的对象里,比较难实现,而且意义不大所以换成了mobx,mobx就是完美解决这个问题的最好方案

@cycallj
Copy link
Author

cycallj commented Jun 12, 2019

谢谢回复,有空去研究下mobx,顺便问下mobx怎么发音 ( ╯□╰ )

@aiyuekuang
Copy link
Owner

应该是莫布克斯吧 _

@xclidongbo
Copy link

额, 摸波插?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants