使用 eventRender 在完整日历 api 中追加子元素?

Append child element in full calendar api using eventRender?

我的应用程序中有一个简单的 SVG,现在处于悬停状态,我想在完整日历中将此 div 动态附加到某个元素 API

UPDATE: Here is my full component

import React, { useState, useEffect, useContext, useRef } from 'react';
import { Calendar as FullCalendar } from '@fullcalendar/core';
import googleCalendarPlugin from '@fullcalendar/google-calendar';
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGridPlugin from '@fullcalendar/timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import calendartopbg from 'assets/images/calendar_bg.png';
import cloud from 'assets/images/calendar_chmurka.png';
import styled from 'styled-components';

const Calendar = () => {
    const [calendar, setCalendar] = useState('');
    const calendarRef = useRef('');

    useEffect(() => {
        if (calendarRef.current) {
             console.log(FullCalendar);
            setCalendar(new FullCalendar(calendarRef.current, {
                plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin, googleCalendarPlugin],
                theme: false,
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'dayGridMonth,listYear',

                  },  
                  views: {
                    day: {
                      titleFormat: 'dddd, MMMM Do YYYY'
                    }
                  },

                  googleCalendarApiKey: 'AIzaSyDcnW6WejpTOCffshGDDb4neIrXVUA1EAE',
                  events: 'en.usa#holiday@group.v.calendar.google.com',
                  eventClick: function(arg) {

                    // opens events in a popup window
                    window.open(arg.event.url, '_blank', 'width=700,height=600');

                    // prevents current tab from navigating
                    arg.jsEvent.preventDefault();
                  },
        eventRender: function(info){
                      console.log(info.el);
                      var imageData = document.getElementById('imageDataContaainer')

                    console.log(imageData)

                    info.el.appendChild(imageData);
                  },
            }));        
        }
    }, [calendarRef.current]);

    console.log(calendar);

    return (
        <>
           <CalendarBackgroundWrapper>
                <img style={imagestyle} src={calendartopbg} />
         </CalendarBackgroundWrapper>

            <CalendarContainer ref={calendarRef}>
                {calendar && calendar.render ? calendar.render(): null}
            </CalendarContainer>
        <div id="imageDataContaainer">
            <svg  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
                <defs>
                    <mask id="image-mask">
                        <circle id="outer" cx="50" cy="50" r="50" fill="white"/>
                        <circle id="inner" cx="50" cy="50" r="25"/>
                    </mask>
                </defs>
            </svg>
        </div>

        </>
    )
}

export default Calendar;

在控制台上我可以看到这个 div ,然后出现以下错误

app.js?1:121281 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at Calendar.eventRender (app.js?1:121281)

我这里的代码有什么问题?

我不确定您要做什么以及为什么需要 "event render",但 "React way" is conditional rendering 是一个组件。

改变 DOM(如附加子项)是一种反模式,as it's React's responsibility.

const App = () => {
  const [isRender, toggle] = useReducer(p => !p, false);

  return (
    <>
      {isRender && <SVGComponent />}
      <button onClick={toggle}>Render SVG</button>
    </>
  );
};