Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector in React Native for selecting all components

Tags:

react-native

Is there a CSS selector or a kind of designator supported by React Native for selecting all components like body selector in CSS while using with HTML?

We do not select components to style them, unlike we do with html; selecting html elements to be styled, by tagname for example, from css sheet. Conversely, in react, style names put into the components, i.e. into the markup.

like image 473
sçuçu Avatar asked Sep 01 '15 13:09

sçuçu


People also ask

What will be selector to select all the elements?

The * selector selects all elements. The * selector can also select all elements inside another element (See "More Examples").

How do I use the Select option in react-native?

To work with react-native-picker-select , we must import the RNPickerSelect component: import RNPickerSelect from "react-native-picker-select"; This component is then reused in our code to render the select view.

How do I Group A selector?

To group selectors, separate each selector with a comma.


1 Answers

Styling in RN does not work the same way as in CSS. It's deliberate decision, and the idea that the component always has everything that is needed to display it (data, views, styles) and refers to it explicitly.

It's a paradigm shift vs. old HTML/css approach - part of the react concept to not have some global "overrides" defined elsewhere (as you have in CSS). If you want (for example) to define a global font defined for all components, you should define it as a global style that you explicitly use in the component itself. This way looking at the component code, you can reason about the whole of it without guessing about something else overriding parts of your code.

Just to make it clear: it does make writing the code a bit more difficult. You have to use some styles explicitly when you write the code or expose them as properties if you want them to be changed by the component above in the hierarchy. But then - it makes reading the code (and understanding it) a lot easier - you can always easily trace the path to the actual styles used by the given component. Which is IMHO much more important.

like image 169
Jarek Potiuk Avatar answered Sep 19 '22 13:09

Jarek Potiuk