score:-2
To set the state from your browser, stick this somewhere in your component, like in render()
:
globalSetState = function(state){this.setState(state)}.bind(this);
Note: It's important to leave off the var
, as this is what makes the defined function globally accessible.
You can now call globalSetState({x: 'y'})
in your console.
Warning: This is mad ugly, and, like console.log()
for debugging, should be deleted in your live app.
score:1
To set a react components's state from the browser, you can bind a function to the window object that will trigger the set state.
In the react component's constructor, you can do this.
constructor (props){
super(props);
window.changeComponentState = (stateObject) => {
this.setState ({stateObject});
}
}
In the browser console you can do this.
window.changeComponentState ({a:'a'});
WARNING: This is anti-pattern. This will work, but you should never never do this.
score:23
If you have the React devtools extension, you can access the React scope via your browser console with $r
.
First, select the component you wanna act on in the React devtools tab:
Then, use $r
to act on the component, for example read state with $r.state
or set state with $r.setState({ ... })
:
Source: stackoverflow.com
Related Query
- How to set React component state and props from browser
- Set state in React component from props and update when props change?
- how does react props merge state passed from parent component and redux store
- How to pass value to props from component and set state
- How to set state in parent from one child component and access the state in another child component using react and typescript?
- How to initialize the react functional component state from props
- how and when to call a react component methods after state change from redux
- How to from one component set state another component in react native?
- How to set state from props that is passed to the component in react?
- React Final Form. How to set field value from component state
- How to make my component re render after updating props from selector in react and redux-saga?
- how to set react parent component state by a async function and then pass this state to child as props?
- In React Hooks. How to set state to a random number and use that to display a string from an array
- How to set a loading state for react component while sorting and filtering data?
- How can I redirect to another component in react and pass the state that I set in the previous component?
- How to set one component's state from another component in React
- How to set defaultChecked getting value from state React Functional Component Checkbox (React - Hooks)
- How to use template string to create link from props and render image in React component
- How to update state if I have props coming from parent component in React Hooks
- How can I pass props from one component to another using Link and router in react
- How to set state of a react component with a specific item from a returned json object?
- How to pass a json array that comes from backend to child component using props and react hooks?
- How do I set the current component state from the data received as props from the parent component?
- how to customize the shape height and width of a component from the props using react
- How do I manipulate state from a child component using props and spread operator?
- How to update react component state from one component to another, and call any functions from any component
- How to set the state of a component with the information obtained from a promise to avoid memory leaks in react
- How to Set a state of parent component from child component in react js
- React Cannot read property 'bind' of undefined from constructor/componentDidMount and Unable to set state on unmounted component
- React: How to set a component in 'active' state one at a time, and remove 'active' from all other component on click?
More Query from same tag
- Calling a variable from fetch into React render function
- How to use TypeScript union types in react
- Detect button click from WebView in React Native
- Type 'Requireable<string>' is not assignable to type 'Validator<"horizontal" | "vertical" | undefined>'
- React: component's render() is NOT invoked after this.setState() is called
- Are import aliases possible using Typescript
- How do you select a single cell with react-data-grids and use the data in that cell elsewhere
- How does the method menuDataRender() get its input for menuList?
- Cannot read property 'includes' of undefined react checkbox filter
- react router dom pushing user before finishing action
- Monaco editor deltaDecorations changes the style of the whole text instead of just the given range
- How to test a component that renders children as props in enzyme
- React Link cant open heroku url
- Map through an object with children objects- Javascript
- how to write onClick (with arguments) optimized by useCallback in React?
- React and Firebase - cant set the state
- create-react-app web server respond with CORS headers
- How can i toggle a Boolean value correctly for specific object in a array?
- Links are display into two rows (React, css)
- The data in the input box cannot be changed
- What is a more elegant way to dynamically add validation rules to Redux Form Fields?
- Is there a way to make a progess bar which is incremented each time an array row is read?
- After closing Materialize CSS Modal the "modal-overlay" remains - How can we close it without touching the overlay?
- What is most efficient way to handle array object in react reducer?
- Is ther a way to get the sizing of the image to show without distorting?
- Global vs single file coverage thresholds when single file change in commit
- Getting typeError while adding item to cart
- componentdidmount - prop-types validation
- make a custom class globally useable for material-ui
- Pass function by props in react router