Conditionally linking with react-router Link

后端 未结 3 636
孤城傲影
孤城傲影 2021-01-12 08:21

I have a situation in my React component which is: i want some elements to be wrappend in a Link component if this.props.isComingFromModal is false

3条回答
  •  我在风中等你
    2021-01-12 08:52

    My simple functional solution:

    const ConditionalLink = ({ children, to, condition }) => (!!condition && to)
          ? {children}
          : <>{children};
    

    Then you can use it like this:

    
    

提交回复
热议问题