Skip to content

Instantly share code, notes, and snippets.

@alexreardon
Created January 12, 2018 05:03
Show Gist options
  • Save alexreardon/71563676661d5027ccc6b5899496d527 to your computer and use it in GitHub Desktop.
Save alexreardon/71563676661d5027ccc6b5899496d527 to your computer and use it in GitHub Desktop.
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