score:3
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'
}
});
Source: stackoverflow.com
Related Query
- How to reuse the React JS component in React Native
- React Native Hooks - How use useStates in Styles
- How to apply global styles with CSS modules in a react app?
- How to detect when a React Native app is closed (not suspended)?
- How do I exit/shut down a React Native app?
- How to add SCSS styles to a React project?
- How do you make the ListHeaderComponent of a React Native FlatList sticky?
- How to concatenate JSX components in React Native
- How to add sourcemap in React Native for Production?
- How to test React Native Module?
- How to implement radio button in React Native
- How to adjust font size to fit view in React Native for Android?
- How to change background color of react native button
- React Native - how to use local SVG file (and color it)
- How to Position a React Native Button at the bottom of my screen to work on multiple ios devices
- React Native inline styles and performance
- react native how to call multiple functions when onPress is clicked
- React Native External Stylesheet
- How to dim a background in react native modal?
- How to create two columns with space beetwen in react native - flatList
- How to keep scroll position using flatlist when navigating back in react native ?
- How can I present a native UIViewController in React Native? (Can't use just a UIView)
- How to close the modal in react native
- React Native - How to open route from push notification
- How to run socket.io in the background on iOS in a React Native app?
- How in React native destroy an component instance to avoid memory leak and release underlie views objects of native code?
- How do I set a marker in MapView of React Native
- How to draw dashed border style in react native
- How to apply lazy loading in flatlist in react native
- How to set the height of button in React Native Android
More Query from same tag
- Unable to map Firebase db items
- Material UI hide element onClick or when checkbox is checked
- Form created with React doesn't update the backing state object
- How to load a <div> on top of React google map component?
- Mock api calls from Storybook
- Rendering css style applied React stateless functional statement
- useFieldArray react-hook-form
- React state is not being updated using useState()
- react component not working properly when rendered multiple times
- How to create refs in react constructor function in es7?
- On logout redirect to login page
- Why are JS / React much quicker than WebAssembly / Rust?
- Detect click outside component react hooks
- Count time between 2 dates for multiple forms using reactjs
- React, redux component does not update on route change
- Antd Select Component mode multiple, checkbox styling
- How to solve "Element type is invalid" for my React app?
- Both Material-UI radio button are checked
- How to use webpack devServer proxy in create react app
- Unable to Embed redirect using Ternary operator in JSX
- Should I Configure Babel Through .babelrc or WebPack?
- hook change state doesn't update context provider's value?
- How to handle multiple inputs to create nested state property
- React native cannot read property 'navigate' is undefined error
- Module build failed: SyntaxError: Unexpected token regarding quotation marks
- Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead
- Sort API Response without Storing the Data using JavaScript
- Why am I unable to access a Redux store in a child React component?
- How to auto progress from one input to another in a form?
- setState inside for loop doesn't update state correctly