0
Hello, I’m new to React Native and I’m having problems to pass the status of a Reducer to a component I made. the same is as follows:
import React from 'react'
import { connect } from 'react-redux'
import { View, Text } from 'react-native'
class Foo extends React.Component {
render() {
const foo = !!this.props.isEnabled ? 'sim!' : 'não!';
return <View><Text>{foo}</Text></View>
}
}
const mapStateToProps = state => {
console.log(state);
return { isEnabled: state.fooReducer.isEnabled }
}
const mapDispatchToProps = {}
export default connect(mapStateToProps, mapDispatchToProps)(Foo);
The Redux is working and I can view the status change from the console.log()
that I put in the mapStateToProps
I just can’t pass that state to the component and use it to manipulate the render.
What I need to do to use that state within the render?
And if you call the
mapStateToProps
within the functioncomponentDidMount()
?– sant0will
I don’t understand. As far as I know, mapStateToProps is part of Redux... in theory there is no way I can get it inside the componentDidMount()
– LeandroLuk
Your
mapStateToProps
returns the isEnabled which as you said is working, assigning the return of the same incomponentDidMount()
you, I believe, will be able to use it inrender()
– sant0will
Could you give me an example? of how to use this?
– LeandroLuk