Reputation:
I wanna get the data from my Redux storage, not an error :)
In a function based component I always do like this
...
import { useSelector } from 'react-redux';
export deafult function App(...){
...
const someData = useSelector(state => state.someData);
...
return (...)
}
...
But when it comes to a class based component I want smth like this, but I get an error :(
...
import { useSelector } from 'react-redux';
export default class App extends Component {
constructor(...){
...
const someData = useSelector(state => state.someData);
...
}
render(...)
}
...
Upvotes: 5
Views: 5582
Reputation: 107
Hooks only works with functional components
Instead of useSelector you can pass you props from react-redux like this
import React from 'react'
import {connect} from 'react-redux'
class App extends React.Component{
...
//Your data from react-redux can be called like this.props.someData
const someData = this.props.someData;
...
}
const mapStateToProps = state => {
return {
someData: state.someData
}
}
export default connect(mapStateToProps)(App)
Upvotes: 7