Skip to content

Instantly share code, notes, and snippets.

@navarroaxel
Created October 10, 2018 15:10
Show Gist options
  • Save navarroaxel/8186a94f08878f54c6ae195ed43806e9 to your computer and use it in GitHub Desktop.
Save navarroaxel/8186a94f08878f54c6ae195ed43806e9 to your computer and use it in GitHub Desktop.
// formThemeContext.js
const FormThemeContext = createContext({
radio: {},
textInput: {},
integerInput: {}
});
export default FormThemeContext;
const DwellingCharacteristics = () => (
<FormThemeContext.Provider
value={
textInput: {
color: 'blue'
},
radio: {
container: {
backgroundColor: 'red'
}
}
}
>
<Section {...{chapter}}/>
</FormThemeContext.Provider>
)
// ..... Radio/index.js
import styles from './styles';
const Radio = () => (
<FormThemeContext.Consumer>
{({radio = {}}) => (
<View
style={composeStyles(styles.container, radio.container)}
>
...
</View>
)}
</FormThemeContext.Consumer/>
)
// formThemeContext.js
const defaultTheme = {
radio: {},
textInput: {},
integerInput: {}
};
export createFormTheme = (theme) => ({...defaultTheme, ...theme});
const FormThemeContext = createContext(defaultTheme);
export FormThemeContext;
const DwellingCharacteristics = () => (
<FormThemeContext.Provider
value={createFormTheme(
textInput: {
color: 'blue'
},
radio: {
container: {
backgroundColor: 'red'
},
...
}
)}
>
<Section {...{chapter}}/>
</FormThemeContext.Provider>
)
// ..... Radio/index.js
import styles from './styles';
const Radio = () => (
<FormThemeContext.Consumer>
{({radio}}) => (
<View
style={composeStyles(styles.container, radio.container)}
>
...
</View>
)}
</FormThemeContext.Consumer/>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment