关于hooks+ts接收参数问题

如果params不给props赋值的话,props可以显示所有参数,给props赋值后只能从params里面取,有其它方法可以接收剩余参数吗?这些剩余参数都是不固定的,比如我想取到传过来的date属性值
interface params = {

count: number,

}
const ChildComp: React.FC<any> = (props:params) => {...}
...

const ParentComp = () => {

    const [count,setCount] = useState(0);

    useEffect(() => {
        console.log(count);
    }, [count]);

    return (
        <ChildComp count={count} date='20211210' />
    )
}



interface params = {
    count: number,
}

const ChildComp: React.FC<any> = (props:params) => {,

  return (
    <div>{props.count}</div>
  )
}
export default ChildComp;





阅读 2.2k
1 个回答

是这个意思?

const Child: FC<{
  count: number;
  data: string;
  foo: () => void;
}> = ({ count, ...rest }) => {
  console.log(count, rest.data, rest.foo);
  return <></>;
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题