皮棉发誓缺乏性能

时间:2020-03-16 10:41:14

标签: reactjs typescript react-redux

当调用组件时,“ redux”具有“连接”并且调用时需要转移属性,短绒棉将在没有属性的情况下发誓

Component1

std::copy

Component2

interface Component1Props {
   id: numbers;
   users: any[];
}

const Component1: React.FC<Component1Props> = ({
  id,
  users
}) => {
  ...
};


const mapStateToProps = ({ users }: any) => ({
  users
});

export default connect(mapStateToProps, null)(Component1);

如何解决?

1 个答案:

答案 0 :(得分:0)

您可能要使用他们官方文件中的这种方法

typing-the-connect-higher-order-component

ConnectedProps

使用ConnectedProps<T>导出的@types/react-redux^7.1.2类型从connect推断道具的类型。

import { connect, ConnectedProps } from 'react-redux'

interface RootState {
}
const mapState = (state: RootState) => ({
})
const mapDispatch = {
}
const connector = connect(mapState, mapDispatch)

type PropsFromRedux = ConnectedProps<typeof connector>
type Props = PropsFromRedux & {
  backgroundColor: string
}

const MyComponent = (props: Props) => (
  <div style={{ backgroundColor: props.backgroundColor }}>
    <button onClick={props.toggleOn}>
      Toggle is {props.isOn ? 'ON' : 'OFF'}
    </button>
  </div>
)
export default connector(MyComponent)