MCPcopy Create free account
hub / github.com/reactstrap/reactstrap / getDerivedStateFromProps

Method getDerivedStateFromProps

src/Carousel.js:88–112  ·  view source on GitHub ↗
(nextProps, prevState)

Source from the content-addressed store, hash-verified

86 }
87
88 static getDerivedStateFromProps(nextProps, prevState) {
89 let newState = null;
90 let { activeIndex, direction, indicatorClicked } = prevState;
91
92 if (nextProps.activeIndex !== activeIndex) {
93 // Calculate the direction to turn
94 if (nextProps.activeIndex === activeIndex + 1) {
95 direction = 'end';
96 } else if (nextProps.activeIndex === activeIndex - 1) {
97 direction = 'start';
98 } else if (nextProps.activeIndex < activeIndex) {
99 direction = indicatorClicked ? 'start' : 'end';
100 } else if (nextProps.activeIndex !== activeIndex) {
101 direction = indicatorClicked ? 'end' : 'start';
102 }
103
104 newState = {
105 activeIndex: nextProps.activeIndex,
106 direction,
107 indicatorClicked: false,
108 };
109 }
110
111 return newState;
112 }
113
114 componentDidUpdate(prevProps, prevState) {
115 if (prevState.activeIndex === this.state.activeIndex) return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected