GithubHelp home page GithubHelp logo

getting TypeError: Cannot add property sourceResource, object is not extensible when clicking on events about react-big-calendar HOT 3 OPEN

bappyasif avatar bappyasif commented on August 28, 2024 1
getting TypeError: Cannot add property sourceResource, object is not extensible when clicking on events

from react-big-calendar.

Comments (3)

AlexW29ChemE avatar AlexW29ChemE commented on August 28, 2024 1

This issue is due to object mutation on the passed in events. The drag-and-drop wrapper is trying to add the "sourceResource" property to the selected event when attempting to move it. I assume redux marks any objects being added to the store as not extensible through the Object.preventExtensions() function to ensure immutability.

CodeSandbox

One solution is to just remap any objects being retrieved from the store so they are treated as new objects and the constraint is no longer applied.

const events = useSelector((state)=>state.event.items)
const remappedEvents = events.map((item) => ({ ...item }))

I do feel this may need to be changed in the library itself, as mutating props is not usually a reccommended approach, this is adding the "sourceResource" property to any passed in events only when that event is being moved which is quite unexpected and likely an unwanted side effect.

from react-big-calendar.

moonbeam-dev avatar moonbeam-dev commented on August 28, 2024 1

@bappyasif @AlexW29ChemE Thank you for bringing this issue to light. I resolved this issue by creating a copy of the draganddrop subfolder code from the library, importing withDragAndDrop from the subfolder, and modifying the one line in the EventWrapper.js to create a copy of the prop using JSON.parse() and JSON.stringify() so the original prop is not mutated following this discussion on StackOverflow

Essentially, changed this one line from:
let extendedEvent = this.props.event
to:
let extendedEvent = JSON.parse(JSON.stringify(this.props.event))

If we are able to get some consensus around the validity of this solution (perhaps @basstager you could chime in as the author of the original code), then hopefully @cutterbl can approve PR #2475 to be merged 🙂

from react-big-calendar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.