How to passing data from component to another component on reactJs using map?

淺唱寂寞╮ 提交于 2019-12-24 23:55:42

问题


I have a react-big-calendar, I want when I click on new event, the dialog of the hour will be having the values of the hour clicked on the new event, for example, I click the mouse from 07:30 to 08:30, so I want to get this hour on my dialog as the value of the input of start and end state, but, I have the same dialog by clicking on the button "Ajouter disponibilité" which his position is above of the calendar, when I click it I will have the hour of the moment, and at both of them I can change it with the clock.

My code sandbox is :

https://codesandbox.io/s/9llpm579py

When I run it, I get the same value is moment for a both of them.

How can I fix it ?


回答1:


https://codesandbox.io/s/8xl25y616j

Because you're passing the required format for those text fields in as parameters to handleAjouter = (start, end), you can just bind them to your first element's start and end. You could use moment like you had, but it doesn't seem necessary.

handleAjouter = (start, end) => {
    this.state.tranches[0].start = start;
    this.state.tranches[0].end = end;
    this.setState({
      start: moment(start).format("HH:mm"),
      end: moment(end).format("HH:mm"),
      clickDisponibilite: true,
      tranches: this.state.tranches,
      openPopupAjout: true
    });
  };

Because your initial element, while it gets its initial value from start and end, its values are inside tranches[0].

So now it pulls those values in https://gyazo.com/d0f887a0fa3d4dfeff56919a7cf94b28



来源:https://stackoverflow.com/questions/55870078/how-to-passing-data-from-component-to-another-component-on-reactjs-using-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!