I learn JavaScript and React Redux and have this question:.
Let's say I have this Redux dispatch
:
dispatch(setLogMessage( () =>{"Connecting to env1", 12340, "connecting"}));
and the reducer is here for the above setLogMessage
is this:
const initialState = {
log: "",
};
case booksActionTypes.LOG_MESSAGE: {
return {
...state,
log: action.payload,
};
}
And in the mapStateToProps
it looks like this:
const [theLog, addLog] = useState([]);
useEffect(() => {
if (props.log !== "") {
addLog([...theLog, createData(props.log)]);
}
}, [props.log]);
function createData(message, timestamp, type) {
console.log('s');
return { message, timestamp, type };
}
The problem is I play around and wanted to learn the arrow functions in this context and wanted to have the above props.log
, to be a function to resolve the above () =>{"Connecting to env1", 12340, "connecting"})
and pass it to function createData(..
.
Hope you understand my question!