I want to change all text's color of a html which was rendered by react-native-render-html
Change text color of a html which was rendered by react-native-render
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
I want to change all text's color of a html which was rendered by react-native-render-html
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Nov 28, 2023, 5:00 AM EST
To change the text color of an HTML rendered by
react-native-render-html, you can make use of therenderersPropsprop provided by the library. This prop allows you to customize the rendering of specific HTML elements.import React from 'react'; import { View, Text } from 'react-native'; import HTML from 'react-native-render-html'; const CustomTextRenderer = ({ children }) => ( {children} ); const App = () => { const renderersProps = { p: { renderers: { text: CustomTextRenderer, }, }, span: { renderers: { text: CustomTextRenderer, }, }, // Add more HTML elements as needed }; const htmlContent = 'This is a sample HTML. '; return ( ); }; export default App;we define a custom text renderer component
CustomTextRendererthat wraps the text with acomponent and applies a red color style. We then pass this custom renderer to therenderersPropsprop for theandHTML elements.Chandru TS73 reputationPosted Dec 4, 2023, 12:55 AM EST
source={{html: source}}
contentWidth={width}
baseStyle = {baseStyle}
/>
const baseStyle = {
color: 'black'
}
This works for all the tags commonly