首页 > 解决方案 > React-select 自定义 Option 对象也不接收 innerprops.key

问题描述

在 react-select 中创建自定义选项对象时,我没有收到文档中所需的 innerProps 对象的“键”属性。https://react-select.com/props#creatable-props > 组件 > 选项。尽管如此,我还是收到了 innerprops 的其余属性(id、onClick、onMouseOver、tabIndex)和一个新的 onMouseMove。有没有人有同样的问题?

无论如何,该对象似乎都可以工作,但我害怕在没有钥匙的情况下离开 React 重新加载。

自定义选项:

function Option(props) {
  return (
    <MenuItem
      ref={props.innerRef}
      selected={props.isFocused}
      component="div"
      style={{
        fontWeight: props.isSelected ? 500 : 400,
      }}
      {...props.innerProps}
    >
      {props.children}
    </MenuItem>
  );
}

标签: react-select

解决方案


推荐阅读