I want my component know if some library is already loaded. To know that from any context i connect it to the "library" reducer of my store to my component.
I also pass it a configuration object this.props.dataObject
from the parent where the component has been called. Like this:
class GoogleButton extends Component {
render() {
if (this.props.libraries.google) {
return <a id='sharePost' className='google_icon'></a>
} else {
return null
}
}
componentDidUpdate() {
gapi.interactivepost.render('sharePost', this.props.dataObject)
}
}
function mapStateToProps(state) {
return { libraries: state.libraries }
}
export default connect(mapStateToProps)(GoogleButton)
The reducer that handles the libraries state is like this:
let newState = {...state}
newState[action.libraryName] = action.state
return newState
When I change the library state componentDidUpdate
works. The problem is when i change the prop inherited by the parent this.props.dataObject
. In that case is where componentDidUpdate wont fire. If i remove the connect
from the component it works as espected. I'm missing something here?
GoogleButton
? Also you might want to check the other lifecycle methods:componentDidMount
,componentWillReceiveProps
– Scarysize