10 examples of 'prevstate in react' in JavaScript

Every line of 'prevstate in react' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
31static getDerivedStateFromProps(nextProps: Props, prevState: State): State {
32 let newState = prevState;
33
34 if (nextProps.value.type !== prevState._backgroundType) {
35 newState = {
36 ...prevState,
37 backgroundType: nextProps.value.type,
38 _backgroundType: nextProps.value.type
39 };
40 }
41
42 return newState === prevState ? prevState : null;
43}
9prev(state: State): State {
10 return state
11}
280value: function componentDidUpdate(_, prevState) {
281 var _props2 = this.props,
282 isOpened = _props2.isOpened,
283 onRest = _props2.onRest,
284 onMeasure = _props2.onMeasure;
285
286
287 if (this.state.currentState === IDLING) {
288 onRest();
289 return;
290 }
291
292 if (prevState.to !== this.state.to) {
293 onMeasure({ height: this.state.to, width: this.content.clientWidth });
294 }
295
296 var from = this.wrapper.clientHeight;
297 var to = isOpened ? this.getTo() : 0;
298
299 if (from !== to) {
300 this.setState({ currentState: RESIZING, from: from, to: to });
301 return;
302 }
303
304 if (this.state.currentState === RESTING || this.state.currentState === WAITING) {
305 this.setState({ currentState: IDLING, from: from, to: to });
306 }
307}
68value: function getDerivedStateFromProps(nextProps, prevState) {
69 if ('value' in nextProps && !isEqual(nextProps.value, prevState.prevPropValue)) {
70 var state = DatePanel.propsToState(nextProps);
71 state.prevPropValue = nextProps.value;
72 return state;
73 }
74
75 return null;
76}
33static getDerivedStateFromProps(
34 props: WithInputHandlersProps,
35 state: State
36) {
37 let newState = state;
38 if (props.value !== state._value) {
39 newState = {
40 ...newState,
41 _value: props.value,
42 value: props.value
43 };
44 }
45
46 return newState === state ? null : newState;
47}
34stateFromProps(props) {
35 const { getData, readOnly } = props.blockProps;
36 const initialState = pubsub.get('initialState_' + props.block.getKey());
37 if (initialState) {
38 //reset the initial state
39 pubsub.set('initialState_' + props.block.getKey(), undefined);
40 }
41 return {
42 componentData: getData() || { config: DEFAULTS },
43 readOnly: !!readOnly,
44 componentState: initialState || {},
45 };
46}
56stateFromProps(props) {
57 const { readOnly } = props.blockProps;
58 const initialState = pubsub.get('initialState_' + props.block.getKey());
59 if (initialState) {
60 //reset the initial state
61 pubsub.set('initialState_' + props.block.getKey(), undefined);
62 }
63 return {
64 componentData: this.getData(props),
65 readOnly: !!readOnly,
66 componentState: initialState || {},
67 };
68}
19componentDidUpdate(prevProps: Props) {
20 // Support page recovery
21 if (this.props.children !== prevProps.children) {
22 this.setState({exception: null});
23 }
24}
35value: function getDerivedStateFromProps(nextProps, prevState) {
36 if ('value' in nextProps && !isEqual(nextProps.vlaue, prevState.prevPropValue)) {
37 return {
38 prevPropValue: nextProps.vlaue
39 };
40 }
41
42 return null;
43}
46static getDerivedStateFromProps(nextProps, prevState) {
47 return {
48 explorer: nextProps.explorers[nextProps[idPropertyName]],
49 };
50}

Related snippets