How to migrate react recompose to react hooks?

72 Views Asked by At

I have recently upgrade my react 16 to 18 and now want to migrate recompose to react hooks. Even I don't know what is react recompose and what are the code I have to change to make this work?

Here is my code:

import { compose } from "recompose";

  const handleLogout = () => {
    logout({
      logoutParams: {
        returnTo: window.location.origin,
      },
    });
  };

  const handleChangeProjectName = () => {
    setAnchorActionsElement(null);
    setChangeProjectNameDialogOpen(true);
  };

function Projects(props) {
  const { classes, removeToken } = props;

  return (
    <Grid
      className={classes.container}
      container
      direction="column"
      wrap="nowrap"
    >
      SOME CODE
    </Grid>
);
}

const mapStateToProps = (state) => {
  const { token } = state;
  return { token };
};

const mapDispatchToProps = { removeToken };

Projects.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default compose(
  withStyles(styles),
  connect(mapStateToProps, mapDispatchToProps)
)(Projects);

I tried changing only compose export this:

export default compose(
  withStyles(styles),
  connect(mapStateToProps, mapDispatchToProps)
)(Projects);

to this:

export default function () {
  withStyles(styles);
  connect(mapStateToProps, mapDispatchToProps);
}

But it not worked. What do I have to do, only change the export or some other codes also to do complete migration from recompose to hooks?

0

There are 0 best solutions below