This isn't a question about react-redux hooks like useSelector or useDispatch. I'm curious to know how old school react-redux connect() with a functional component and when it's necessary to use React hooks like useEffect in this example.
Suppose I have this functional component that renders a "Hello world" in green if someReduxData is present, otherwise it render it in red.
const RandomComponent = ({ someReduxData }) => {
const style = {
color: someReduxData ? "green" : "red";
};
return (
<div style={style}>Hello world</div>
);
}
const mapStateToProps = (state) => {
return {
someReduxData: state.someReduxData;
};
};
export default connect(mapStateToProps)(RandomComponent);
Let's say when the component first mounts to the DOM, someReduxData is null. Then it changes state so it's not null anymore. Will this force a re-render of RandomComponent so it renders in green? If not, then I assume I will need to listen for changes on someReduxData with useEffect()?
connectworks the same regardless of class vs function component. - Zachary Haber