How to set navigationOptions on stateless component with Typescript

后端 未结 4 1271
有刺的猬
有刺的猬 2020-12-16 13:18

I have a react component like

const Example = () => (...);

Using react-navigation I would normally apply naviga

4条回答
  •  悲&欢浪女
    2020-12-16 13:44

    The key idea is to specify correct type for Example constant. Probably, react-navigation already provides that type. But, you can also extend build-in React interface smth like this:

        interface NavStatelessComponent extends React.StatelessComponent {
            navigationOptions?: Object
        }
    
        const Example: NavStatelessComponent = () => {
            return (
                
                   ...
                
            )
        }
    
        Example.navigationOptions = {
            /*
            ...
            */
        }
    
        Example.propTypes = {
            /*
            ...
            */
        }
    

提交回复
热议问题