question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Discussion] How to extend existing Core Components in React-Native?

See original GitHub issue

So, I have written a library, react-native-webview-bridge, for WebView to handle message passing between React-Native and Javascript in WebView. It is based on WebViewJavascriptBridge.

So since there is no way to extend WebView.ios.js, I ended up copying the source code and renamed and modified it, which is not ideal. What I want is a way to extend a React-Native’s Core Components.

I’m looking for some suggestions to guide me through this. How would you guys extend the Core Component? Is it actually possible to extend any React’s implementation?

Just to be clear, I am talking about the Javascript portion of React-Native’s Components not the objective-c part.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
wilsonpagecommented, Apr 29, 2016

@alinz do you have an example of how this could translate for Android?

2reactions
brentvatnecommented, Jul 8, 2015

Currently there are a couple of ways to do this, that I know of:

  • You can wrap it in another component that layers on the functionality
  • You can subclass it if you must, eg:
class SuperText extends Text {

  render() {
    return (
      <View>
        <Text style={{color: 'pink', textAlign: 'center'}}>*******************</Text>
        {super.render()}
        <Text style={{color: 'purple', textAlign: 'center'}}>:) :) :) :) :)</Text>
      </View>
    )
  }

}

screen shot 2015-07-08 at 2 12 43 pm

Read more comments on GitHub >

github_iconTop Results From Across the Web

Composition vs Inheritance - React
React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components.
Read more >
Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >
Higher-Order Components - React
Concretely, a higher-order component is a function that takes a component and returns a new component. const EnhancedComponent = higherOrderComponent( ...
Read more >
React Components, Elements, and Instances – React Blog
In this traditional UI model, it is up to you to take care of creating and destroying child component instances. If a Form...
Read more >
React.Component
The only method you must define in a React.Component subclass is called render() . All the other methods described on this page are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found