Categories
JavaScript Answers React Native Answers

How to fix Objects are not valid as a React child error with React Native?

Spread the love

Sometimes, we want to fix Objects are not valid as a React child error with React Native.

In this article, we’ll look at how to fix Objects are not valid as a React child error with React Native.

How to fix Objects are not valid as a React child error with React Native?

To fix Objects are not valid as a React child error with React Native, we should make sure we’re returning strings, null, a component, an array of components, or a fragment.

For instance, we write:

import * as React from 'react';
import { View, Text } from 'react-native';
import Constants from 'expo-constants';
import AssetExample from './components/AssetExample';
import { Card } from 'react-native-paper';

export default function App() {
  return (
    <View>
      <Text>hello world</Text>
    </View>
  );
}

to render a View with a Text component inside it.

Therefore, we see ‘hello world’ displayed.

Conclusion

To fix Objects are not valid as a React child error with React Native, we should make sure we’re returning strings, null, a component, an array of components, or a fragment.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *