iamacup / react-native-markdown-display

React Native 100% compatible CommonMark renderer
MIT License
590 stars 169 forks source link

Infinity rerenders on heading1/2 rules. #133

Closed dennisbouwpas closed 10 months ago

dennisbouwpas commented 3 years ago

I'm trying to make a scroll to the heading1. But when I'm trying to save Y position of the element it's constantly rerendering. and in the console I see 0 245 0 245 0 245 etc...

I also tried to make an if-else statement to prevent infinity rerenders but then I always have a Y = 0 all the time.

`const myRules = { heading1: (node, children) => ( <View key={node.key} style={mdStyles.indexHeaderWrapper} onLayout={(event) => { const { layout } = event.nativeEvent; setY(layout.y) }}

{1}

<Text numberOfLines={1} ellipsizeMode="tail" style={mdStyles.headerText}

{children} ) };`