Skip to content

Commit b2895b3

Browse files
authored
Ref error fix (#99)
* changed ref to TranscriptEditor * changed ref in src/index.js
1 parent 2648224 commit b2895b3

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class App extends React.Component {
2121
analyticsEvents: [],
2222
fileName: 'Kate Darling Ted Talk'
2323
};
24+
25+
this.transcriptEditorRef = React.createRef();
2426
}
2527

2628
loadDemo() {
@@ -99,7 +101,7 @@ class App extends React.Component {
99101

100102
exportTranscript = () => {
101103
// eslint-disable-next-line react/no-string-refs
102-
const { data, ext } = this.refs.transcriptEditor.getEditorContent(this.state.exportFormat);
104+
const { data, ext } = this.transcriptEditorRef.current.getEditorContent(this.state.exportFormat);
103105
this.download(data, `${ this.state.mediaUrl }.${ ext }`);
104106
}
105107

@@ -200,7 +202,7 @@ class App extends React.Component {
200202
isEditable={ this.state.isTextEditable }
201203
sttJsonType={ this.state.sttType }
202204
handleAnalyticsEvents={ this.handleAnalyticsEvents }
203-
ref={ 'transcriptEditor' }
205+
ref={ this.transcriptEditorRef }
204206
/>
205207
<hr/>
206208
<label>Components Analytics</label>

src/lib/TranscriptEditor/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TranscriptEditor extends React.Component {
2929
showTimecodes: true,
3030
showSpeakers: true
3131
};
32+
this.timedTextEditorRef = React.createRef();
3233
}
3334

3435
static getDerivedStateFromProps(nextProps) {
@@ -69,10 +70,10 @@ class TranscriptEditor extends React.Component {
6970
}
7071

7172
ifPresentRetrieveTranscriptFromLocalStorage = () => {
72-
if (this.refs.timedTextEditor!== undefined) {
73-
if (this.refs.timedTextEditor.isPresentInLocalStorage(this.props.mediaUrl)) {
73+
if (this.timedTextEditorRef.current!== undefined) {
74+
if (this.timedTextEditorRef.current.isPresentInLocalStorage(this.props.mediaUrl)) {
7475
console.info('was already present in local storage');
75-
this.refs.timedTextEditor.loadLocalSavedData(this.props.mediaUrl);
76+
this.timedTextEditorRef.current.loadLocalSavedData(this.props.mediaUrl);
7677
} else {
7778
console.info('not present in local storage');
7879
}
@@ -155,7 +156,7 @@ class TranscriptEditor extends React.Component {
155156
this.setState({ timecodeOffset: timecodeOffset },
156157
() => {
157158
// eslint-disable-next-line react/no-string-refs
158-
this.refs.timedTextEditor.forceUpdate();
159+
this.timedTextEditorRef.current.forceUpdate();
159160
});
160161
}
161162

@@ -218,11 +219,11 @@ class TranscriptEditor extends React.Component {
218219
}
219220

220221
getEditorContent = (exportFormat) => {
221-
return this.refs.timedTextEditor.getEditorContent(exportFormat);
222+
return this.timedTextEditorRef.current.getEditorContent(exportFormat);
222223
}
223224

224225
handleSaveTranscript = () => {
225-
return this.refs.timedTextEditor.localSave(this.props.mediaUrl);
226+
return this.timedTextEditorRef.current.localSave(this.props.mediaUrl);
226227
}
227228

228229
render() {
@@ -276,7 +277,7 @@ class TranscriptEditor extends React.Component {
276277
isPauseWhileTypingOn={ this.state.isPauseWhileTypingOn }
277278
showTimecodes={ this.state.showTimecodes }
278279
showSpeakers={ this.state.showSpeakers }
279-
ref={ 'timedTextEditor' }
280+
ref={ this.timedTextEditorRef }
280281
handleAnalyticsEvents={ this.props.handleAnalyticsEvents }
281282
/>;
282283

0 commit comments

Comments
 (0)