Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在嵌入式日历小部件中计划事件时,如何运行代码?_Javascript_Reactjs_Calendly - Fatal编程技术网

Javascript 在嵌入式日历小部件中计划事件时,如何运行代码?

Javascript 在嵌入式日历小部件中计划事件时,如何运行代码?,javascript,reactjs,calendly,Javascript,Reactjs,Calendly,当我使用Calendly计划事件时,我使用Calendly API标记显示事件创建日期,但该日期仅在重新加载页面后显示,而我希望在计划事件后在控制台中更新一次 下面是代码 import React,{useState,useffect}来自“React”; 从“axios”导入axios; 从'react calendly'导入{InlineWidget}; 常量日历=()=>{ const[state]=useState() useffect(()=>{ axios({ 方法:“get”, 网

当我使用Calendly计划事件时,我使用Calendly API标记显示事件创建日期,但该日期仅在重新加载页面后显示,而我希望在计划事件后在控制台中更新一次

下面是代码

import React,{useState,useffect}来自“React”;
从“axios”导入axios;
从'react calendly'导入{InlineWidget};
常量日历=()=>{
const[state]=useState()
useffect(()=>{
axios({
方法:“get”,
网址:'https://v1.nocodeapi.com/user/calendly/hobiiHVeoqPxvtTc',
}).然后(功能(响应){
//成功
console.log(response.data.collection[response.data.collection.length-1];
}).catch(函数(错误){
//处理错误
console.log(错误);
})
},[国家])
返回(
);
}
滚动导出默认值;

如果要在安排Calendly事件时运行某些代码,则需要侦听Calendly iframe将发布回主机页的消息。这是我的一部分。这是大概的代码

import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { InlineWidget } from 'react-calendly';

const isCalendlyScheduledEvent = (e) => {
  return e.data.event &&
         e.data.event.indexOf('calendly') === 0 &&
         e.data.event === 'calendly.event_scheduled'
}

const Calendly = () => {

    const [state] = useState()

    useEffect(() => {
      window.addEventListener(
        'message',
        (e) => {
          if (isCalendlyScheduledEvent(e)) {
            axios({
              method: 'get',
              url: 'https://v1.nocodeapi.com/user/calendly/hobiiHVeoqPxvtTc',
            }).then(function (response) {
              // handle success
              console.log(response.data.collection[response.data.collection.length - 1].created_at);
            }).catch(function (error) {
              // handle error
              console.log(error);
            })
          }
        }
      )
    }, []) // notice the empty array as second argument - we only need to run it once, equivalent to the old componentDidMount behavior
    
    return (
        <div>
            ...    
        </div>

    );

}
    
export default Calendly;

添加了使用react calendly中的CalendlyEventListener的示例。如果对你有用的话,我会的!
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { InlineWidget, CalendlyEventListener } from 'react-calendly';

const Calendly = () => {
    const onEventScheduled = () => {
      axios({
        method: 'get',
        url: 'https://v1.nocodeapi.com/user/calendly/hobiiHVeoqPxvtTc',
      }).then(function (response) {
        // handle success
        console.log(response.data.collection[response.data.collection.length - 1].created_at);
      }).catch(function (error) {
        // handle error
        console.log(error);
      })
    }
    
    return (
      <div>
        ...

        <CalendlyEventListener onEventScheduled={onEventScheduled} />
      </div>

    );

}
    
export default Calendly;