我正在尝试为我的 React 组件创建一些样式,如下所示:
var styles = StyleSheet.create({
/*Pinout*/
/*GPIO Shapre*/
gpio_outer: {
background: '#222222',
borderRadius: 5,
height: 26,
width: 26,
},
})
我正在添加它
编译代码并尝试在浏览器上运行后,我从浏览器控制台得到了这个:
TypeError: StyleSheet.create is not a function
你知道会发生什么吗?提前致谢
最佳答案
StyleSheet 是 React-Native 的一部分,而不是常规 ReactJS 的一部分。但是,您可以实例化一个样式对象并像在 RN 中一样使用它。
render() {
const style = {
margin: '0.5em',
paddingLeft: 0,
listStyle: 'none'
};
return <ul style={style}>item</ul>;
}
快速的谷歌搜索也让我找到了一些 react js 库,它们为您提供了您正在寻找的抽象。
关于reactjs - TypeError : StyleSheet. 创建不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37879771/