search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

this in undefined in the addEvent example

Related article: React Scheduler Component Tutorial
Asked by Olivier Rossel
11 days ago.

Hello I get a message from my IntelliJ when I try to use the code for the ref attribute and the onTimeRangeSelected attribute. The this in these codes might be uninitialized. And it indeed is undefined at runtime.

Is it something related to using Typescript? or using the DayPilotScheduler inside an fonction-based component and not a class-based component?

Any help is welcome.

Answer posted by Dan Letecky [DayPilot]
11 days ago.

This hint is correct, you can't use "this" in a functional React component. You'll need to create a variable instead:

const Scheduler = () => {
    let scheduler: DayPilot.Scheduler;

    return (
            <DayPilotScheduler ref={component => {
              scheduler = component && component.control;
            }} />
New Reply
This reply is
Your name (optional):