admin管理员组文章数量:1289868
I've just started my react native app and having some troubles. I have some experience with react but that doesnt seem to be helping much. The div surrounding the Text is meant to be my app header so Im trying to style it but for some reason it throws an error saying is NOT recognised?
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Header from './ponents/Header';
class App extends React.Component {
return (
<View style={styles.container}>
<div>
<Text>HELLO WORLD</Text>
</div>
<StatusBar style='auto' />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Thanks
I've just started my react native app and having some troubles. I have some experience with react but that doesnt seem to be helping much. The div surrounding the Text is meant to be my app header so Im trying to style it but for some reason it throws an error saying is NOT recognised?
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Header from './ponents/Header';
class App extends React.Component {
return (
<View style={styles.container}>
<div>
<Text>HELLO WORLD</Text>
</div>
<StatusBar style='auto' />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Thanks
Share Improve this question asked Mar 2, 2021 at 16:31 Mo MiahMo Miah 3481 gold badge4 silver badges14 bronze badges 1- You can't add div element into react native app. Maybe you can add the pakage to use Div: npmjs./package/react-native-div – R3tep Commented Mar 2, 2021 at 16:35
4 Answers
Reset to default 3divs don't exist in react-native. You should use View instead.
React Native and React are related in their structure and logic, but the tags that you use will be different. The div tag on React Native is the View Component.
Instead of using:
<div>Test</div>
You should use
<View><Text>Test<Text/></View>
And some others:
<button> will be <Button>
<input> will be <Input>
<form> does not exist, you should use <View>
<ul><li>Test Item</li></ul> you should use <Flatlist /> or a [].map
Like so but...
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Header from './ponents/Header';
const App = () => {
return (
<View style={styles.container}>
<div>
<Text>HELLO WORLD</Text>
</div>
<StatusBar style='auto' />
</View>
);
}
export default App;
const div = (props) => {
return (
<View>{props.children}</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
...you should get familiar with the ponents that are already built in. You are able to extend react native to support those tags but it is wierd to do so.
You couldn't use html element inside react native. You may be use react-native-webview to load html
本文标签: javascriptHow to add div to React NativeStack Overflow
版权声明:本文标题:javascript - How to add div to React Native? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741445401a2379167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论