Mrugesh
Mrugesh

Reputation: 4517

A valid react element(or null) must be returned. You nay have returned undefined,an array or some other invalid object (React Native)

I am trying to compile react native project. the code for the file in which error is :

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

const Header = () =>
{
const {textStyle} =styles;
return
(
    <View>
    <Text style={textStyle}>Albums!</Text>
    </View>
    );
};

const styles = {
textStyle:{
    fontSize:20
}
};

export default Header;

Upvotes: 0

Views: 588

Answers (1)

Matt Aft
Matt Aft

Reputation: 8936

You're not returning anything, you have to have the open paran on the same line as the return statement.

return ( 
  <View>
    <Text style={textStyle}>Albums!</Text>
  </View>
);

You can also refactor it to:

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

const {textStyle} =styles;

const Header = () => (
  <View>
    <Text style={textStyle}>Albums!</Text>
  </View>
)

const styles = {
  textStyle:{
    fontSize:20
 }
};

export default Header;

Upvotes: 4

Related Questions