2016-11-22 55 views
0

我试图编译反应本地项目。该文件的代码中的错误是:必须返回有效的react元素(或null)。您不仅如此已返回undefined,数组或其他一些无效的对象(阵营母语)

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; 

回答

4

你不返回任何东西,你必须有在同一行return语句开放巴兰。

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

也可以将它重构为:

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; 
+0

是的,它的工作! –

相关问题