Getting error when trying to use Redux Toolkit with MUI ToggleButtonGroup component

The error message begins as:

Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.

The handleChange function ran without error until I tried to update redux state with a dispatcher.

This worked fine:

const [alignment, setAlignment] = React.useState('12');

const handleChange = (event, newAlignment) => {
    setAlignment(newAlignment);
};

But I want to elevate the state to redux toolkit. Changing the function as below caused the error:

const dispatch = useDispatch;

const handleChange = (event, newAlignment) => {
    dispatch(setNbTasks(newAlignment));
};

`
Any help would be most appreciated, I’m new to this!

I tried a couple of things, but got nowhere, the details are above.