0

I have a HOC that is connected to redux like this way:

const withSignIn = (WrappedComponent: React.FC<WithSignInProps>) => {
  const mapStateToProps = ({ auth }: AuthRootState) => ({
    error: auth.error,
    loading: auth.loading
  });

  const mapDispatchToProps = {
    signIn
  };

  return connect(mapStateToProps, mapDispatchToProps)(WrappedComponent);
};

export default withSignIn;

I'm missing return type on function withSignIn but I don't know what type should I cast my function, it's returning a connect() function there, any hint?

1 Answer 1

1

I think what you're looking is there https://redux.js.org/recipes/usage-with-typescript#typing-the-connect-higher-order-component

to be more accurate this lines

const connector = connect(mapState, mapDispatch)

// The inferred type will look like:
// {isOn: boolean, toggleOn: () => void}
type PropsFromRedux = ConnectedProps<typeof connector>
type Props = PropsFromRedux & {
  backgroundColor: string
}

So I guess what you return is

React.FC<WithSignInProps & PropsFromRedux>

I didn't have enough code to try it myself, tell me if it works for you :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.