Skip to content
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

Fix dragAndDrop EventWrapper.js error: cannot add property 'X', object is not extensible #2475

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

moonbeam-dev
Copy link
Contributor

Fix for error: cannot add property 'X', object is not extensible

Above console error appears when using the Resource Drag and Drop feature of react big calendar to move events. I narrowed the issue down to this code in the addons/dragandDrop/EventWrapper.js:
let extendedEvent = this.props.event

Per the linked discussion on Stack Overflow, it is not possible to modify this.props directly. The solution is to create a copy of the props using JSON.parse() and JSON.stringify()

Thus the modified code that I have gotten working without error is:
let extendedEvent = JSON.parse(JSON.stringify(this.props.event))

…t is not extensible

Fix for error: cannot add property 'X', object is not extensible

An error appears when trying to modify this.props. The solution is to create a copy of the props using JSON.parse() and JSON.stringify()

https://stackoverflow.com/questions/55567386/react-cannot-add-property-x-object-is-not-extensible
@cutterbl
Copy link
Collaborator

cutterbl commented Jan 5, 2024

The issue I see here is in the handling of dates. Event start and end dates must currently be true JS Date objects. By using this methodology to 'copy' an event, these values would be converted to strings. Perhaps a better way of handling this would be:
let extendedEvent = {....this.props.event};

@moonbeam-dev
Copy link
Contributor Author

Thank you so much Steve @cutterbl ! I tested your solution and can confirm it is working well, minus the one extra dot 😉
let extendedEvent = {...this.props.event};

When I edited my previous PR to match your solution, it created a new commit. Still learning the ropes here, so not sure if this is the correct process.

Thank you again and let me know if you need me to make any changes for the approval.

@cutterbl cutterbl merged commit 0c4826a into jquense:master Jan 8, 2024
1 check passed
Copy link

github-actions bot commented Jan 8, 2024

🎉 This PR is included in version 1.8.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants