Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to use a custom functional component in react-native?

how to use a functional custom component in react native??? i actualy build a login functional component like a custom react but not exsist a "div" i made a "View"
why should this not work??

    import React from 'react';
    import { Text, View } from 'react-native';

    const Login = () => {
    return (
        <View>
          <Text>Hi</Text>
        </View>
      );
    }
    export default Login;

--------------------------------- 
    import React from 'react';
    import {Login} from './components/Login/Login';
    import { Text, View } from 'react-native';
    
    const App = () => {
        return (
        <View>
          <Login/>
       </View>
        )
     }
     export default App;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’ve got your named exports and default exports turned around.

This would work instead:

 import React from 'react';
    import { Text, View } from 'react-native';

    const Login = () => {
    return (
        <View>
          <Text>Hi</Text>
        </View>
      );
    }
    export default Login;

--------------------------------- 
    import React from 'react';
    import Login from './components/Login/Login';
    import { Text, View } from 'react-native';
    
    const App = () => {
        return (
        <View>
          <Login/>
       </View>
        )
     }
     export default App;

When you export default Login, you must import it as a default import with import Login from ./components/Login/Login`

Here is an Expo Snack with the working code as well

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading