score:0
<View style={[subComponentStyling, {backgroundColor: blue}]}>
...
</View>
score:1
// Context lets us pass a value deep into the component tree
// without explicitly threading it through every component.
// Create a context for the current style (with "{display:none}" as the default).
const SubComponentStyleContext = React.createContext({display:none});
class App extends React.Component {
render() {
// Use a Provider to pass the current style to the tree below.
// Any component can read it, no matter how deep it is.
// In this example, we're passing "{display:block}" as the current value.
return (
<SubComponentStyleContext.Provider value={{display:block}}>
<MainComponent />
</SubComponentStyleContext.Provider>
);
}
}
// A component in the middle doesn't have to
// pass the style down explicitly anymore.
function MainComponent(props) {
return (
<div>
<SubComponent />
</div>
);
}
function SubComponent(props) {
// Use a Consumer to read the current style context.
// React will find the closest theme Provider above and use its value.
// In this example, the current style is "{display:block}".
return (
<SubComponentStyleContext.Consumer>
{style => /*use style here as you want*/}
</SubComponentStyleContext.Consumer>
);
}
Source: stackoverflow.com
Related Query
- Passing props to sub components Reactjs
- React passing onClick as props to sub components required?
- Reactjs Passing props down 2 components
- Reactjs - passing same props to multiple child components
- Passing values to other components using props in reactjs
- Passing functions in ReactJS as props for components
- Different behavior in passing the same props in 2 components in ReactJS
- React: Passing down props to functional components
- Passing a function with parameters through props on reactjs
- Passing data child to parent functional components in reactjs
- React memo components and re-render when passing function as props
- Reactjs passing methods as props to child
- Connecting child components to store vs connecting parent component to store and passing down props
- Typescript & React: Passing props between components vs default props
- Passing props in protected route reactjs
- React Native: Passing props between components and componentWillMount() method
- Passing props to children components with react-router v4
- Passing data to child components in reactjs
- reactjs passing array of components
- React - Passing fetched data from API as props to components
- Reactjs - create factory, passing props into component
- Passing multiple methods in props ReactJS
- Passing an array of Components as a Props in React
- Passing Props between components
- Undefined when passing props to siblings reactJS
- `react-router` warning solution and passing root props to sub routes
- passing flask python variables on the server to reactjs as props
- styled components - passing props to GlobalStyle
- Avoid passing down props using Styled Components and Typescript
- React - functional components keep re-render when passing functions as props
More Query from same tag
- Change focus of fields with ref
- All buttons are clicked at the same time instead of the specific one clicked
- Multiple API handling through Axios in react application
- Formik: How to reset form after confirming on dialog
- filter items based on multiple properties
- React Scheduler customize Appointment Form
- React component issues with state, setState and render
- Graphql Bad Request on page load
- Prevent URL encoding that is removing equals signs from URL
- react + redux - 401 - unauthorized - missing headers in Request Headers
- When toggle divs why the input values stays
- TypeError: Cannot read property 'exists' of undefined
- Code coverage missing even when the lines are hit
- How to pass prop to component from array of components in React
- React on different subdomains
- I wanted to save two values in this.props.onChange but only is saving the last
- UseState doesn't update in componentDidMount lifecycle method
- how to check onclick function is fired or not in react?
- Next.js - Pull data at specific times
- Child component does not render properly
- using variables from component in input tag
- Material UI floating label
- How to manage a selector that accepts arguments with yield select?
- How to place text at the start and another at end in the same alert tage in react bootstrap
- How to set onClick event of button to multiple functions (depending on prop) in React?
- How do i add functionality to my nav dots in my image slider?
- ESLint: Can "react/sort-prop-types" errors be auto-fixed?
- ReactJs component syntax, whats the difference?
- React Link not working on same url type dom
- How to align react-bootstrap modal relative to the button clicked