Create React Native component which renders title of component by destructuring 'props' argument

Arjun Moudgil

I am looking to make a button component which allows the consumer of the component to input the title of the button. I have seen this work before but am now getting an error when I try to run the code.

Error message: 'Text strings must be rendered within a component.

AppButton code:

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

function AppButton({title}) {
    return (
        <View style={styles.button}>
            <Text style={styles.text}>{title}</Text>
        </View>
    );
}

const styles = StyleSheet.create({
    button: {
        backgroundColor: "dodgerblue",
        borderRadius: 25,
        justifyContent: "center",
        alignItems: "center",
        padding: 15,
        width: '100%',
    },
    text: {
        color: "white",
        fontSize: 18,
        textTransform: 'uppercase',
        fontWeight: 'bold',
    }
})

export default AppButton;

Output code:

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import AppButton from './components/AppButton';

export default function App() {
  return (
    <View style={styles.container}>
      <AppButton title = "Push Me"/>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
user15517071

Import from 'react-native' instead of 'react-native-web'.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Pass component tag as a props in react native

React / React Native + Enzyme: How to test if a component renders it's children?

Pass props to child component - React Native

React Native - measure component when props recieved

Get navigation props in an independent component React Native

Destructuring ImmutableJS Map for React Component Props

react router native renders linked component over previous one

Difference between Component{} vs Component<Props>{} in react/react native?

React functional component destructuring

Custom button Component in React Native is not accepting props

React props destructuring when passing to component

Destructuring this.props into Component

React destructuring state to pass into component props

How to Pass Props to Modal Component in React Native

Dynamically Create Component in react native

React native deep linking unwanted component renders even with cleanup function

Bizarre problem with React component which renders wrong HTML code

React Native - pass class to component as props

Create dynamic Component React (Native)

component props destructuring error

React Native child component not receiving updated props

React Native: Component rerender but props has not changed

Create a custom react native component

Multiple component renders in react

child component without props re-renders even with react mem

how to create a wrapper that changes the props for the component in react

react native using multi props to same component

REACT Component renders and then disappears

Which component renders child component if parent is componentless