File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,17 @@ class Demo extends Component {
6161 return < div >
6262 < h1 > react-sequence-viewer Demo</ h1 >
6363 < button onClick = { this . handleOnClick } > Click me</ button >
64- < MyComponent onSubpartSelected = { subPart } onMouseSelection = { mouseClick } legend = { exampleLegend } coverage = { exampleSequenceCoverage } sequence = { this . state . seq } showLineNumbers = { true } toolbar = { true } search = { true } badge = { true } title = "My Protein" />
64+ < MyComponent
65+ onSubpartSelected = { subPart }
66+ onMouseSelection = { mouseClick }
67+ legend = { exampleLegend }
68+ coverage = { exampleSequenceCoverage }
69+ sequence = { this . state . seq }
70+ showLineNumbers = { true }
71+ toolbar = { true }
72+ search = { true }
73+ badge = { true }
74+ title = "My Protein" />
6575 </ div >
6676 }
6777}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export default class ReactSequenceViewer extends Component {
77 constructor ( props ) {
88 super ( props ) ;
99 this . handleChange = this . handleChange . bind ( this ) ;
10+ this . handleRef = this . handleRef . bind ( this ) ;
1011
1112 if ( props . selection && props . selection . length > 0 && props . coverage && props . coverage . length > 0 ) {
1213 console . warn ( "The selection and coverage options are not compatible with each other." ) ;
@@ -59,8 +60,10 @@ export default class ReactSequenceViewer extends Component {
5960 }
6061
6162 // Re-render if the component has updated.
62- componentDidUpdate ( ) {
63- this . callRender ( ) ;
63+ componentDidUpdate ( prevProps , prevState ) {
64+ if ( this . props !== prevProps ) {
65+ this . callRender ( ) ;
66+ }
6467 }
6568
6669 // Remove the event listener when the component is unmounted.
@@ -78,14 +81,18 @@ export default class ReactSequenceViewer extends Component {
7881 }
7982 }
8083
84+ handleRef ( div ) {
85+ this . _div = div ;
86+ }
87+
8188 // Render a div with the sequence-viwer widget in it.
8289 render ( ) {
8390 const { id, sequence, className } = this . props ;
8491 // Create the container div and store a reference to it once it is mounted
8592 // in the DOM. The componentDidMount function above will then get called
8693 // and render the widget.
8794 return (
88- < div className = { className } id = { this . props . id } ref = { ( div ) => this . _div = div } > </ div >
95+ < div className = { className } id = { this . props . id } ref = { this . handleRef } > </ div >
8996 ) ;
9097 }
9198}
You can’t perform that action at this time.
0 commit comments