First of all it would be ideal if you put this variable object as a theme in Provider
of styled-components
, thus:
import { ThemeProvider } from 'styled-components';
const cores = {
main: "#333",
institutional: "blue"
};
function App() {
return (
<ThemeProvider theme={cores}>
<Componente />
</ThemeProvider>
);
}
This allows you to use the theme variables on all components without having to import the object, aside from the fact that changes in the Preview are reflected everywhere by the app.
And then, in the export
do Component, you do so, for example:
import styled from 'styled-components'
import { View } from 'react-native'
export default styled(View)`
background-color: ${props => props.theme.main};
`;
It works. I think it kind of Overkill use styled-components
in React Native apps, but this is a topic for another discussion...
You couldn’t do it
var cor = "#333"
and then in colors you putcores = { main: cor }
? It’s just an idea even because I don’t know much about JS, but it will pass :)– hugocsl