[英]Advice needed for ReactJS Equivalent of React-Native-Web stylesheet.flatten
So we are trying to remove React-Native-Web from our codebase, and I was wondering what the ReactJS equivalent of stylesheet.flatten
was?所以我们试图从我们的代码库中删除 React-Native-Web,我想知道 ReactJS 的stylesheet.flatten
等价物是什么?
We are using it like this;我们是这样使用它的;
const flattenMyStylesheets = StyleSheet.flatten(styles);
const style = Object.keys(flattenMyStylesheets || {}).length ? { style: flattenMyStylesheets } : {};
return {
...
props: {
...style
}
};
Failing that what would be the best way to swap this out没有什么是最好的交换方式
You don't usually go the StyleSheet way with native React.你通常不会使用原生 React 的 StyleSheet 方式。
I'd recommend using either a styled-components
approach, or with React you can use pure objects for styling instead of relying on the StyleSheet
RN API.我建议使用styled-components
方法,或者使用 React,您可以使用纯对象进行样式设置,而不是依赖StyleSheet
RN API。 See here看这里
Note: I'm a React Native + React dev注意:我是 React Native + React 开发者
So the short answer is that no, there is no equivalent.所以简短的回答是,不,没有等价物。 I investigated and felt that lodash.flatten
could work as a substitute, with a little tweaking, but in my case we converted the stylesheets to an object, and just removed the dependency on stylesheet.flatten
我调查并觉得lodash.flatten
可以作为替代品,稍作调整,但在我的例子中,我们将样式表转换为一个对象,并删除了对stylesheet.flatten
的依赖
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.