账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react怎样指定传入的属性必须是某个类型的组件
    38
    0
    有Parent和Child两个组件,我想指定Parent的children只能是Child,而不能是其它的元素。下面ParentProps.children的类型为ReactElement<ChildProps>[]也不能实现,传入非Child的元素组件也不报错。这个应该怎么实现?type ChildProps = { name: string}const Child:FC<ChildProps> = ({name}) => { return <div>{name}</div>}type ParentProps = { children: ReactElement<ChildProps>[] //怎样指定children只能是Child}const Parent:FC<ParentProps> = ({children}) =>{ return <div>{children}</div>}const App = () => {/* return ( <Parent> <span>不是Child</span> </Parent> )*/ return ( <Parent> <Child name='abc123' /> <Child name='xyz456' /> </Parent> )}
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 兵馬乱 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部