Created
January 12, 2018 05:03
-
-
Save alexreardon/71563676661d5027ccc6b5899496d527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class Student extends Component<{ student: Person }> { | |
render() { | |
// Renders out a draggable student | |
} | |
} | |
class InnerList extends Component<{ students: Person[] }> { | |
// do not re-render if the students list has not changed | |
shouldComponentUpdate(nextProps: Props) { | |
if(this.props.students === nextProps.students) { | |
return false; | |
} | |
return true; | |
} | |
// You could also not do your own shouldComponentUpdate check and just | |
// extend from React.PureComponent | |
render() { | |
return this.props.students.map((student: Person) => ( | |
<Student student={student} /> | |
)) | |
} | |
} | |
class Students extends Component { | |
render() { | |
return ( | |
<Droppable droppableId="list"> | |
{(provided: DroppableProvided, snapshot: DroppableStateSnapshot) => ( | |
<div | |
ref={provided.innerRef} | |
style={{ backgroundColor: provided.isDragging ? 'green' : 'lightblue' }} | |
> | |
<InnerList students={this.props.students} /> | |
{provided.placeholder} | |
</div> | |
)} | |
</Droppable> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment