Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In react-native we use styleSheet.create. What do we use in reactjs?

Tags:

In react-native we use styleSheet.create. What do we use in reactjs?

Thanks for the help!

https://github.com/romseguy/redux-store-visualizer

I dont see any use of style here but there is styling. how did he achieve this or did i miss out anything?

like image 891
phongyewtong Avatar asked Jan 21 '16 15:01

phongyewtong


People also ask

What is the use of StyleSheet create in React Native?

A StyleSheet is an abstraction similar to CSS StyleSheets. Instead of creating a new style object every time, StyleSheet helps to create style objects with an ID which is further used to reference instead rendering it again.

Which method is used to create StyleSheet in React?

create() ​ Creates a StyleSheet style reference from the given object.

Is there StyleSheet in React?

Inline styles are the most direct away to style any React application. Styling elements inline doesn't require you to create a separate stylesheet. Style applied directly to the elements as compared to styles in a stylesheet also have higher precedence.


Video Answer


1 Answers

The analogous option would be to do something like the following:

let styles = {   container: {     backgroundColor: 'red'   } } 

Like one of the comments stated above, the StyleSheet call is unecessary because CSS is supported already on the browser.

Finally, just call the style inline in your render function's return statement:

render() {   ...   return (     <div style={styles.container} />   ) } 

Of course, aside from that, you have a few other options as well, like using plain CSS stylesheets and classes/tags, but this is probably the most similar option to what you're used to.

like image 139
Christine Cha Avatar answered Sep 23 '22 05:09

Christine Cha