jsdf / react-native-htmlview

A React Native component which renders HTML content as native views
ISC License
2.7k stars 466 forks source link

Update HTMLView TS definitions to support class components #338

Open CostachescuCristinel opened 2 years ago

CostachescuCristinel commented 2 years ago

Currently, HTMLView's definitions specify the following props to accept function components only: NodeComponent, RootComponent, TextComponent

However, the source code that uses these props, only uses destructuring assignment to extract these from the HTMLView's props, and then creates these components as JSX tags:

RootComponent: https://github.com/jsdf/react-native-htmlview/blob/457751bcd832ba2018f54a1ffe43761a6ff34154/HTMLView.js#L119 NodeComponent: https://github.com/jsdf/react-native-htmlview/blob/457751bcd832ba2018f54a1ffe43761a6ff34154/htmlToElement.js#L150 TextComponent: https://github.com/jsdf/react-native-htmlview/blob/457751bcd832ba2018f54a1ffe43761a6ff34154/htmlToElement.js#L134

This approach is compatible for use with both functional and class components. In fact, I am using class components for these, and there are no problems.

Except: the TS definitions will issue a warning about failed prop types: Warning: Failed prop type: Invalid prop 'TextComponent' of type 'object' supplied to 'HtmlView', expected 'function'.

Can you please update the TS definitions to fix this?