JSX and styling

React Native views are written using JSX (JavaScript XML), an extension to the ECMAScript standard. JSX combines both logic and mark-up into the same file.

JSX is used to achieve separation of concerns, rather than separation of technologies. This means that instead of having separate files for mark-up, styles and behaviour of components, all that is combined into a single file for each separate component.

React Native includes a simplified implementation of CSS for styling objects. Styles are declared right inside the JSX file you’re styling, which enforces you to write modular styles for your modular components, instead of having a global namespace for styles like in CSS.

Styles can be written in three different ways: inline, as plain JavaScript objects or with Stylesheet.create. Both Eiseman (2016) and Holmes & Bray (2015) recommend Stylesheet.create as the best choice, which makes each style declaration immutable and guarantees styles will be loaded only once during the application’s lifecycle.

Comments

Popular posts from this blog

Size & Dimensions & onLayout

Data - Networking - Fetch

Absolute & Relative