8000 [bug] Cannot add property chosen, object is not extensible · Issue #149 · SortableJS/react-sortablejs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[bug] Cannot add property chosen, object is not extensible #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dyyz1993 opened this issue May 5, 2020 · 6 comments
Closed

[bug] Cannot add property chosen, object is not extensible #149

dyyz1993 opened this issue May 5, 2020 · 6 comments

Comments

@dyyz1993
Copy link
dyyz1993 commented May 5, 2020

when item is object , [...list] is error .

onChoose(evt: SortableEvent) {
    const { list, setList } = this.props;
    const newList = [...list];
    newList[evt.oldIndex!].chosen = true;
    setList(newList, this.sortable, store);
  }

Uncaught TypeError: Cannot add property chosen, object is not extensible

@dyyz1993 dyyz1993 closed this as completed May 5, 2020
@dyyz1993 dyyz1993 reopened this May 5, 2020
@dyyz1993 dyyz1993 closed this as completed May 5, 2020
@dyyz1993 dyyz1993 reopened this May 5, 2020
@dyyz1993
Copy link
Author
dyyz1993 commented May 5, 2020 8000
import {produce} from 'immer';

onChoose(evt: SortableEvent) {
    const { list, setList } = this.props;
    const newList =  produce(list,(draft)=>{
        draft[evt.oldIndex!].chosen = true;
    })
    
    setList(newList, this.sortable, store);
  }

this is no problme!!!

@waynevanson
Copy link
Collaborator

@dyyz1993
Can you please follow the bug issue template provided? I'm not sure what you're question is.

@Developer-Nijat
Copy link

Maybe helpful

<ReactSortable
    tag='ul'
    list={list.map(x => ({ ...x, chosen: true }))} // solution
    setList={newState => dispatch(reOrderList(newState))}
>

@itboos
Copy link
itboos commented Apr 15, 2022

Maybe helpful

<ReactSortable
    tag='ul'
 
8000
   list={list.map(x => ({ ...x, chosen: true }))} // solution
    setList={newState => dispatch(reOrderList(newState))}
>

thanks, it helped me !

@theAtaya
Copy link

Basically the same issue/bug as this one 237, and my comment from there. So this might be fixed in v6.1.5. but unfortunately it's not published.
Also one other note, the other solution is to make that object list mutable. There are a lots of ways to do this but one that comes to mind quickly is this hacky one, for example:

<ReactSortable
    tag='ul'
    list={JSON.parse(JSON.stringify(list))} // solution
    setList={newState => dispatch(reOrderList(newState))}
>

@shantanu-kulkarni
Copy link

This worked out for me

<ReactSortable
list={questions.map((q) => ({ ...q }))}
setList={(newState) => {
const newOptions = newState.map((opt) => ({ ...opt }));
dispatch(updateQuestionsOrder(newOptions));
}}
animation={300}
swap
className="space-y-4 w-full"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
0