React-sortable-hoc: when I write in the input,it unblure every time

Created on 3 Jan 2019  路  5Comments  路  Source: clauderic/react-sortable-hoc

Most helpful comment

You are likely creating your enhanced SortableElement components within the render method (if so, move it outside of the component definition), or using the key property incorrectly.

All 5 comments

can you provide a working sample in codepen or codesandbox to show what you mean?

You are likely creating your enhanced SortableElement components within the render method (if so, move it outside of the component definition), or using the key property incorrectly.

I had this problem, but I have to create the enhanced component dynamically. My solution was to use React's memo hook like this:

const DraggableForm = React.useMemo(()=> SortableElement(viewFor(type, "form")), [type])

My components are not created dynamically, so created outside of the render method. I did try @gunn's solution by moving it into the render function with the hook but that does not solve the issue. My keys are unique so that is also not what is causing the rerender. Any help would be appreciated.

Codesandbox: https://codesandbox.io/s/agitated-almeida-jvp6q?fontsize=14
Edit agitated-almeida-jvp6q

PS. I used immer to handle the immutable state changes but it could just as well be done with a standard Array.slice and destructuring of array or whatever other method to change the state. That is not the source of the problem. It seems to be creating a new div when options change, even if keys stay the same

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sir4ur0n picture Sir4ur0n  路  3Comments

iv10 picture iv10  路  4Comments

ashishtechuz picture ashishtechuz  路  4Comments

botoxparty picture botoxparty  路  3Comments

arackaf picture arackaf  路  3Comments