Report a warning when using props data as items.
See original GitHub issueCode:
Component.js:
import {SortableContainer, SortableElement} from 'react-sortable-hoc';
let introModuleList = this.props.introModuleList;
const SortableItem = SortableElement(({value}) => {
return <div className="module">
<Button onClick={() => this.deleteModule(value.moduleOrder)}>删除</Button>
<div>
{this.getCurrentModule(value)}
</div>
</div>;
});
const SortableList = SortableContainer(({items}) => {
return (
<div>
{items.map((item, index) =>
<SortableItem key={`item-${index}`} index={index} value={item} />
)}
</div>
);
});
return <SortableList items={introModuleList} onSortEnd={this.onSortEnd} />;
onSortEnd = ({oldIndex, newIndex}) => {
this.props.changeModuleOrder(oldIndex, newIndex);
};
Reducer:
import {arrayMove} from 'react-sortable-hoc';
arrayMove(initialState.introModuleList, oldIndex, newIndex)
Result:
warning.js:45 Warning: setState(…): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the SortableList component.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >Each child in a list should have a unique "key" prop - Stack ...
What causes this error? I'm looking for a definitive list. ... Two elements with same keys will throw the same warning. The warning...
Read more >About Proposition 65 - OEHHA - CA.gov
Proposition 65 requires businesses to provide warnings to Californians about ... These chemicals can be in the products that Californians purchase, ...
Read more >Warning: Each Child in a List Should Have a Unique 'key' Prop
If the key is an index, reordering an item in the array changes it. Then React will get confused and re-render the incorrect...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @ekrokowski, thanks for pointing that out. Just shipped
0.4.12
with that change@sag1v Read my comment…
In the
handleSortEnd
function -> move this:after the setState (or just to the end of the function)
Just like in my fork: https://github.com/ekrokowski/react-sortable-hoc/blob/51f2c4d3ac763639e66fbd6659cdd8c5fd568cbe/src/SortableContainer/index.js#L302