@@ -55,7 +55,7 @@ class ChatBot extends Component {
5555 this . speak = speakFn ( props . speechSynthesis ) ;
5656 }
5757
58- componentWillMount ( ) {
58+ componentDidMount ( ) {
5959 const { steps } = this . props ;
6060 const {
6161 botDelay,
@@ -98,6 +98,23 @@ class ChatBot extends Component {
9898 chatSteps [ firstStep . id ] . message = firstStep . message ;
9999 }
100100
101+ const { recognitionEnable } = this . state ;
102+ const { recognitionLang } = this . props ;
103+
104+ if ( recognitionEnable ) {
105+ this . recognition = new Recognition (
106+ this . onRecognitionChange ,
107+ this . onRecognitionEnd ,
108+ this . onRecognitionStop ,
109+ recognitionLang
110+ ) ;
111+ }
112+
113+ if ( this . content ) {
114+ this . content . addEventListener ( 'DOMNodeInserted' , this . onNodeInserted ) ;
115+ window . addEventListener ( 'resize' , this . onResize ) ;
116+ }
117+
101118 const { currentStep, previousStep, previousSteps, renderedSteps } = storage . getData (
102119 {
103120 cacheName,
@@ -127,31 +144,15 @@ class ChatBot extends Component {
127144 } ) ;
128145 }
129146
130- componentDidMount ( ) {
131- const { recognitionEnable } = this . state ;
132- const { recognitionLang } = this . props ;
133-
134- if ( recognitionEnable ) {
135- this . recognition = new Recognition (
136- this . onRecognitionChange ,
137- this . onRecognitionEnd ,
138- this . onRecognitionStop ,
139- recognitionLang
140- ) ;
141- }
142-
143- if ( this . content ) {
144- this . content . addEventListener ( 'DOMNodeInserted' , this . onNodeInserted ) ;
145- window . addEventListener ( 'resize' , this . onResize ) ;
146- }
147- }
148-
149- componentWillUpdate ( nextProps , nextState ) {
150- const { opened } = nextProps ;
151-
152- if ( opened !== undefined && opened !== nextState . opened ) {
153- this . setState ( { opened } ) ;
147+ static getDerivedStateFromProps ( props , state ) {
148+ const { opened, toggleFloating } = props ;
149+ if ( toggleFloating !== undefined && opened !== undefined && opened !== state . opened ) {
150+ return {
151+ ...state ,
152+ opened
153+ } ;
154154 }
155+ return state ;
155156 }
156157
157158 componentWillUnmount ( ) {
0 commit comments