phongyewtong phongyewtong - 3 months ago 21
Javascript Question

is it possible to separate var styles = StyleSheet.create from React.component into different script in react native?

is it possible to separate var styles = StyleSheet.create from React.component into different script in react native?

Answer

that's possible. just create a js file with this pattern:

'use strict';

var React = require('react-native');

var myStyles = React.StyleSheet.create({
   style1: { },
   style2: { }
)}

module.exports = myStyles;

then in your component js use require to use that style sheet e.g. assuming your style js file is named phongyewtong.js

var s = require('../the/path/to/phongyewtong');

usage:

<View style = {s.style1} />
Comments