Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use react native elements UI with native base?

I have a project mostly written Native Base components. But in some cases I want to use React Native Elements. I just want to know is it possible to use them seperately.

For some components I will just use React Native Elements like Avatar component. Not importing both of them together, I mean just one UI Toolkit.

like image 420
Adem Özsayın Avatar asked Apr 05 '19 16:04

Adem Özsayın


People also ask

Is NativeBase GOOD FOR React Native?

Recommended by Awesome React Native NativeBase was added to the list of Frameworks of Awesome React Native and it is used by numerous React lovers across the world.

Does React Native use native UI?

What are Native UI components in React Native? Under the hood, React Native uses native components like UIView and UIImageView in iOS and exports them to the JavaScript layer. We use these components in our daily development process.


1 Answers

yes you can use components from Native Base and React Native Elements at the same time as long as they are not called the same in the same component. Let me explain:

The following App is a simple example of having two components from both libraries:

import { Button, ThemeProvider } from 'react-native-elements';
import {  Header } from 'native-base';

const MyApp = () => {
  return (
    <ThemeProvider>
      <Header>                  //Is rendered from the Native Base library
      <Button title="Hey!" />   //Is rendered from the React Native Elements library
    </ThemeProvider>
  );
};

You might get an issue if you try to do the following because it will throw a "duplicate declaration error":

import { Button, ThemeProvider } from 'react-native-elements';    //Button is imported
import { Button, Header } from 'native-base';                     //Button is imported a second time

const MyApp = () => {
  return (
    <ThemeProvider>
      <Button>                   
        <Text>Click Me!</Text>
      </Button>                 
      <Button title="Hey!" />   
    </ThemeProvider>
  );
};

In this code you defined the same component twice (Button) from two different libraries. React Native will not render that component. If you take it out of one of the two import statements it gets rendered with the corresponding component from the library you import it from.

Hope that helps.

like image 86
Benjamin Heinke Avatar answered Sep 22 '22 06:09

Benjamin Heinke