0

So,I'm fetching html from my server and I render it with library:react-native-render-html

Some parts of the string are rendering fine but some of them are like this :

enter image description here

Here is the code:

 <Text style={styles.description}>
          {/* <Text>Testing...</Text> */}
          {currentPostDetails === null || currentPostDetails === undefined ? (
            'Loading...'
          ) : (
            <HTML
              html={currentPostDetails.text.replaceAll(
                'font-family:',
                '&quot;";',
              )}
            />
          )}
        </Text>

Any suggestions please?

6
  • it seems like a library issue. Did you. try creating an issue on this library's github page ? Commented Dec 16, 2020 at 17:12
  • @BoraSumer not yet,I'm not sure yet, maybe the problem is in me Commented Dec 17, 2020 at 5:50
  • @user14587589 i’ve just noticed that you’ve used the html prop instead of the source one which was listed on the docs. Any reason for this? Commented Dec 17, 2020 at 5:56
  • 1
    I changed that too but still did not work Commented Dec 17, 2020 at 5:57
  • <HTML baseFontStyle={{fontFamily: 'normal'}} source={{ html: currentPostDetails.text.replaceAll( 'font-family:', '&quot;";', ), }} /> Commented Dec 17, 2020 at 5:58

1 Answer 1

1

I believe the <Text> component you used to wrap the child components is at fault. <Text> works best when it is rendering plain text instead of complex component like <HTML>.

Try wrapping the child components with the <View> component instead, like this:

<View style={styles.description}>
  {/* <Text>Testing...</Text> */}
  {currentPostDetails === null || currentPostDetails === undefined ? (
    <Text>Loading...</Text>
  ) : (
    <HTML
      html={currentPostDetails.text.replaceAll(
        'font-family:',
        '&quot;";',
      )}
    />
  )}
</View>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.