I'm trying to abstract a portion of this example from using local React hooks to storing the information in Redux.
In particular, the Popover menu requires anchorEl
to be specified in order to anchor to a parent <HTMLElement>
for positioning. The above example from MaterialUI implements the useState
hook to store and change this property:
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
When I try to convert this to Redux,
dispatch(accountMenuSlice.actions.setAnchorEl(event.currentTarget));
it ends up trying to store non-serializable <HTMLElement>
, which is not advisable, yielding the following warning/error
react_devtools_backend.js:2430 A non-serializable value was detected in an action, in the path: `payload`.
Value: <button>…</button>
Take a look at the logic that dispatched this action:
{type: "ACCOUNT_MENU_KEY/setAnchorEl", payload: button.MuiButtonBase-root.MuiIconButton-root.MuiIconButton-colorInherit.MuiIconButton-edgeEnd}
What is the canonical React-Redux method to pass elements/references between atomic components without elevating abstractions into parent components?