reactjs - How can I modify the props of one child component from a separate child component? -


i working on scheduling application using reactjs & flux. in application, user need able select specific shift , assign employee cover it. employee assignment occur clicking on employee's name in separate list.

component structure follows:

  • schedule app component
    • employee list component
      • employee list item component
    • calendar component
      • month component
        • day component
          • shift component

after selecting shift clicking on it, (there 2 - 5 shifts on given day) able click on employee list item , have value of employeename prop (this.props.employeename) assigned selected shift's shiftassignee prop (this.props.shiftassignee).

the data both calendar , employees generated when application starts, , stored separate objects in local storage 'calendar' , 'employees' respectively. have data updated as part of flux data flow can retain instead of regenerating every time app starts, wiping previous data, that's not immediate concern.

the basic structure of data looks pretty follows:

calendar:

{     "monthname": "may",     "days": [         {             "daydate": 1,             "dayname": "friday",             "shifts": [                 {                     "shiftname": "day shift",                     "required": true,                     "shiftassignee": "",                     "shiftlength": 12                 }                 //remaining shifts             ],         }         //remaining days     ] } 

employees:

[     {         "name": "f. last",         "totalhours": 32,         "availablehours": 32,         "assignments": [],         "commitment": 0.8     }     //remaining employees ] 

i don't know if more information needed or if i'm overlooking crucial consideration. if more information needed, let me know.

i don't believe need concerned relationship between 2 child components.

in flux application, data flows in topmost component , passed down children. looking @ way, believe question can rephrased as: "how child component change data flux store?"

i've written rough example in codepen: http://codepen.io/jhubert/pen/zgjedp

it's lightweight conceptual version of flux store / dispatcher built one. i don't recommend copying example; it's concept we're after.

essentially, want employee list item component modify data , let natural cascading data flow work there.

# not real code. kind of coffeescript not real. _data = { { { shiftassignee: '' } } } scheduleappcomponent.setstate = _data employeelistitem.onclick = setshiftassigneeondata() scheduleappcomponent.setstate = _data 

this stuff covered @ high level in flux overview under structure , data flow.

hope that's helpful! luck!


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -