【问题标题】:react-native-render-html Anchor tagreact-native-render-html 锚标记
【发布时间】:2022-08-12 19:50:39
【问题描述】:

我尝试在 \'a\' 标记上创建一个函数 onPress,但这不起作用。 我的包是\"react-native-render-html\": \"^6.0.5\",

 <RenderHTML
        source={newHtml}
        contentWidth={width}
        tagsStyles={tagsStyles}
        renderersProps={{a: {onPress: () =>console.log(\'press\')}}}
        WebView={WebView}
        renderers={tableRenderers}
/>

    标签: react-native


    【解决方案1】:

    您需要将其发送到渲染器道具

    const CustomRenderHtml = ({ html, ...props }) => {
       return (
          <Box {...props} width="100%">
             <RenderHtml contentWidth={'100%'} source={html} renderers={renderers} />
          </Box>
       )
    }
    
    const renderers = {
       a: ARenderer
    }
    
    function ARenderer({ TDefaultRenderer, ...props }) {
       const onPress = () => console.log('presesd')
       return <TDefaultRenderer {...props} onPress={onPress} />
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2013-09-07
      相关资源
      最近更新 更多