react-redux#MapStateToPropsParam TypeScript Examples

The following examples show how to use react-redux#MapStateToPropsParam. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: connectWithCleanUp.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
connectWithCleanUp = <
  TStateProps extends {} = {},
  TDispatchProps = {},
  TOwnProps = {},
  State = {},
  TSelector extends object = {},
  Statics = {}
>(
  mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
  mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
  stateSelector: StateSelector<TSelector>
) => (Component: ComponentType<any>) => {
  const ConnectedComponent = connect(
    mapStateToProps,
    mapDispatchToProps
    // @ts-ignore
  )(Component);

  const ConnectedComponentWithCleanUp: FunctionComponent = props => {
    const dispatch = useDispatch();
    useEffect(() => {
      return function cleanUp() {
        dispatch(cleanUpAction({ stateSelector }));
      };
    }, []);
    // @ts-ignore
    return <ConnectedComponent {...props} />;
  };

  ConnectedComponentWithCleanUp.displayName = `ConnectWithCleanUp(${ConnectedComponent.displayName})`;
  hoistNonReactStatics(ConnectedComponentWithCleanUp, Component);
  type Hoisted = typeof ConnectedComponentWithCleanUp & Statics;

  return ConnectedComponentWithCleanUp as Hoisted;
}