score:2
Accepted answer
if the default value for bgimage
needs to be determined before app
is rendered, then usually you would do this by passing a prop into the component e.g.
<app bgimage={`url(${logo1})`} />
then in the constructor, you can set this as the default state
class app extends component {
constructor(props) {
super(props);
this.state = {
bgimage: props.bgimage
};
}
}
Source: stackoverflow.com
Related Query
- Managing state when changing backgroundImage
- How to optimize React components with React.memo and useCallback when callbacks are changing state in the parent
- why should you clone react state before changing it or when working on it?
- State variable is changing when accessed from useEffect()
- React hook changing the state variable of wrong component when file input
- redux with router keep state when changing url
- Changing fetch request url dynamically when state updates in React
- React state changing when pushing nested object
- React: trigger onChange on checkbox input when changing checked state programmatically?
- How to preserve children state when changing parents in react?
- How to prevent UUID from changing state when using copy-to-clipboard function?
- React - Infinite loop when changing state from onChange
- When changing one specific state setting, is it necessary to restate all the other ones?
- Mantaining component state when changing component placement
- Inputs not changing when removing list items from state
- State from redux store gets lost/ reset when changing route
- (React-Select hooks) state not changing when React-Select onChange prop handling
- Input not changing when React state changes
- How should I go about changing the state of siblings when a child is clicked in React?
- Child component causing too many renderings on parent component when changing global state in React
- How to dynamically update values in Shopping Cart when one item value is changing in React JS using state in map function?
- Managing State when Passing React Component Constuctor Function to Another Component as Attribute
- React state changing unexpectedly when trying to dynamically change state
- Changing state even when the react-tabs component is not selected
- Failed removeChild when changing state in React
- value is changing when storing in state
- What is the reason for this delay when changing the value of the state variables?
- Why does my React app menu open when I am only changing the state and am not using any CSS?
- Why my component is not changing state when I trigger the function
- Redux UI wont update when changing state of nested array
More Query from same tag
- How to sync firebase with react functional components
- Index.html is missing while generating reactjs build. How can we deploy react and nodejs project to production?
- Validation for Select elements of React-Bootstrap are mis-aligned
- react-route,react-hot-loader.webpack (You cannot change <Router routes>; it will be ignored)
- How to give different styles to mapped object elements?
- How to configure node live server? I'm getting rollbackFailedOptionalerror
- Apollo GraphQL Optimistic Response and updating the store issue
- Is there a way to pass down props to a component implicitly?
- react-google-charts click event not working
- How to access data attributes from event object
- Calling two functions with onClick event
- const { authenticated } = this.props is undefined though I can clearly see it in redux
- want to add logger in my react hook while calling microservice from backend
- Using Cognito Authentication with Elastic Load Balancer
- Using Redirect upon form submission in React
- React Mobile navigation doesn't collapse after click
- Normalizing not nested tree into nested with Normalizr
- Is it possible to get rid of the input field with react-select?
- use Effect not being called as expected
- React eventsource is not closed
- How dispatch is accessible in redux middleware?
- dependent select in react js
- Difference between bind and var self=this?
- How can I place a <dv> after a <Typography> in this code
- why is there no need to execute function using () when it is declared by arrow function?
- Rechartd: Vertical bar chart - set bar thickness
- Is there a way to import the Google Maps API into react without a script tag?
- How to map an array of objects to different components props in React?
- While drawing on a HTML5 canvas using mouse, mouse position is not correctly positioned
- Fluid images in .mdx file