I'm having a little problem with connect(). I thought wrapping all components in Provider is going to work, but turns out it isn't.... So I found that I need to use connect() from react-redux. The problem is i don't know how should I use it. This site is showing some examples but, i don't have any action creators to put inside connect because I don't use them....... Can someone give me some advices? I just want to access my store inside components...
相关问题
- How to toggle on Order in ReactJS
- Refreshing page gives Cannot GET /page_url in reac
- Adding a timeout to a render function in ReactJS
- React Native Inline style for multiple Text in sin
- Issue with React.PropTypes.func.isRequired
相关文章
- Cannot find module 'redux' 怎么解决?
- Why would we use useEffect without a dependency ar
- Is it possible to get ref of props.children?
- Stateless function components cannot be given refs
- React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- Material-UI [v0.x] RaisedButton on hover styles
- Remove expo from react native
You might have better luck with the Redux documentation here.
Here's a simple example of how the connect function works:
What happens above is when you export the
Item
component, you're exporting the wrapped, connected component. Wrapping the component will pass in the propname
from the app state (it will also pass in thedispatch
function as a prop.In order to use your store in your container you need to do two things
Firstly : make use of
mapStateToProps()
. As the name suggests, it maps the state variables from your store to the props that you specifySecondly : You need to connect these
props
to your container. This is whereconnect()
comes into picture. The object returned by themapStateToProps
component is connected to the container. You can import connect fromreact-redux
likeimport {connect} from 'react-redux';
Example