- I am attempting to utilize componentWillReceiveProps in order to change the color of a button.
- When I click on the news channel, the "Get top news" button should update its color.
- In Button.js, my plan is to implement componentWillReceiveProps to handle this functionality.
- This way, once the props are received, I can dynamically update the button's color.
- However, when inspecting the componentWillReceiveProps method in Button.js, no output is being logged.
- After some investigation, I came across this post on Stack Overflow, but unfortunately it hasn't resolved my issue: How do i use componentWillReceiveProps() correctly?
- Could someone provide guidance on how to resolve this problem?
- I've included my code snippet and sandbox link below for reference:
https://codesandbox.io/s/boring-wu-btlre
class Button extends Component {
componentWillReceiveProps(nextprops) {
console.log("componentWillReceiveProps nextprops--->", nextprops);
}
render() {
return (
<div>
<button
onClick={() => {
// getPosts(channel);
// getAlert();
}}
className="btn btn-primary btn-lg btn-block"
>
Get top news
</button>
</div>
);
}
}