是否可能将带有jsdoc子级的文档或渲染道具用作函数?

问题描述 投票:1回答:1

[我正在尝试使用react渲染模式创建包装器组件,但我也想记录通过render / children传递的参数,以例如获得有用的智能感知。

[我试图将自己的组件定义为React.ExoticComponent<React.ConsumerProps<MYTYPE>>,但这意味着将组件声明为<Context.Consumer>,隐藏了输入道具。

const Wrapper = ({children}) => {

    const exampleFunction = () => {} 

    return (
        <div>
            {children({exampleFunction})}
        </div>
    )
}

const ImplementationComponent = () => {

    const exampleFunction = () => {} 

    return (
        <Wrapper>
            {({exampleFunction}) => (
                // <Components...>
            )}
        </Wrapper>
    )
}

我想要实现中的类型检查,以帮助谁使用包装器组件。

reactjs jsdoc
1个回答
0
投票
/** @param {{ children: JSX.Element}} [Props] */

const Wrapper = ({children}) => {...}
© www.soinside.com 2019 - 2024. All rights reserved.