score:3

Accepted answer

What you could do is store all your styles in an object in some file e.g. const containerStyles = { borderRadius: 2 }, export it, then for React Native use the StyleSheets javascript class to create the styles for your div container

import {containerStyles} from '../someFile.js'

const styles = StyleSheets.create({
  container: containerStyles
})

then for React you could do inline styling with the same object, but be aware that not all styles supported in StyleSheets can be used for inline styling, so if you want to do something equivalent there's libraries out there like emotion.js to dynamically load CSS in JS

https://github.com/emotion-js/emotion Heres an example

import {css} from 'emotion'
import {containerStyle} from '../someFile'

const getContainerStyles = css`
  border-radius: ${containerStyle.borderRadius}
`

export default class SomeClass extends Component {
  render() {
    return(
      <div
        style={getContainerStyles}
      >
      </div>
    )
  }
}

I hope this helps

score:0

You could concatenate the style of your new component with the style of container, like below

const styles = StyleSheet.create({
  container: {
    borderRadius: 4,
    borderWidth: 0.5,
    borderColor: '#d6d7da',
  },
  newComponent:{
     // New component style
  }
});

<View style={[styles.container, styles.newComponent]}> 
</View>

score:0

// your component file name  (button.js) 
import React, { Component } from 'react';

// import the style from another file present in the same directory
import styles from 'button.style.js'; 
 // you can reuse this style in another component also

class Button extends Component {
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.buttonText}> Press Me! </Text>
            </View>
        );
    }
}

export default Button;

// your style file  name ( "button.style.js")

import { StyleSheet } from 'react-native';

export default StyleSheet.create({
    container: {
        padding: 10,
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: '#43a1c9',
    },
    buttonText: {
        fontSize: 20,
        textAlign: 'center'
    }
});

Related Query

More Query from same tag