我第一次使用nachos-ui
和Button
尝试了Input
,但是发生了相同的错误
TypeError "Cannot read property 'color' of undefined"
我有些事吗?
"react-native": 0.58.5
"nachos-ui": "^0.2.0-beta.1"
节点版本v10.15.1
import React, { PureComponent } from 'react';
import { View, Text, TextInput } from 'react-native';
import { Button, Bubble } from 'nachos-ui';
class AddPost extends PureComponent {
constructor(props) {
super(props);
}
render() {
return (
<View >
<Button>
Button
</Button>
<Bubble>
Hello, How Are you ?
</Bubble>
</View>
);
}
}
export default AddPost;
答案 0 :(得分:2)
您需要将应用程序包装在主题提供程序中,以nachos-ui
个组件进行渲染。
请参阅:https://github.com/nachos-ui/nachos-ui
从文档中
The ThemeProvider component should be set at the highest level of your app. If it is not, Nachos UI components will NOT render.
import { ThemeProvider } from "nachos-ui";
export default (App = () => (
<ThemeProvider>
<RestOfYourApp />
</ThemeProvider>
));
import React from 'react'
import { View } from 'react-native'
import { Button } from 'nachos-ui'
const App = () => {
return (
<View>
<Button>Button</Button>
</View>
)
}
要使其适合您的情况,请尝试以下操作(请注意,ThemeProvider应该确实位于应用程序的顶层,通常为App.js
):
import React, {PureComponent} from 'react';
import {View, Text, TextInput} from 'react-native';
import {Button,Bubble,ThemeProvider} from 'nachos-ui';
class AddPost extends PureComponent {
constructor(props) {
super(props);
}
render() {
return (
<ThemeProvider>
<View>
<Button >
Button
</Button>
<Bubble>
Hello, How Are you ?
</Bubble>
</View>
</ThemeProvider>
);
}
}
export default AddPost;
希望这会有所帮助!