mirror of https://github.com/grafana/grafana
remove UseState from last 2 stories (#53596)
parent
20caed026f
commit
6cdeeeda3c
@ -1,42 +0,0 @@ |
||||
import { action } from '@storybook/addon-actions'; |
||||
import React, { Component } from 'react'; |
||||
|
||||
interface StateHolderProps<T> { |
||||
logState?: boolean; |
||||
initialState: T; |
||||
children: (currentState: T, updateState: (nextState: T) => void) => React.ReactNode; |
||||
} |
||||
|
||||
export class UseState<T> extends Component<StateHolderProps<T>, { value: T; initialState: T }> { |
||||
constructor(props: StateHolderProps<T>) { |
||||
super(props); |
||||
this.state = { |
||||
value: props.initialState, |
||||
initialState: props.initialState, // To enable control from knobs
|
||||
}; |
||||
} |
||||
// @ts-ignore
|
||||
static getDerivedStateFromProps(props: StateHolderProps<{}>, state: { value: any; initialState: any }) { |
||||
if (props.initialState !== state.initialState) { |
||||
return { |
||||
initialState: props.initialState, |
||||
value: props.initialState, |
||||
}; |
||||
} |
||||
return { |
||||
...state, |
||||
value: state.value, |
||||
}; |
||||
} |
||||
|
||||
handleStateUpdate = (nextState: T) => { |
||||
this.setState({ value: nextState }); |
||||
}; |
||||
|
||||
render() { |
||||
if (this.props.logState) { |
||||
action('UseState current state')(this.state.value); |
||||
} |
||||
return this.props.children(this.state.value, this.handleStateUpdate); |
||||
} |
||||
} |
Loading…
Reference in new issue