github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/web/src/Context.js (about)

     1  import React from 'react';
     2  
     3  const Context = React.createContext({});
     4  
     5  export default Context;
     6  
     7  export function GroupProvider({ groups, children, ...rest }) {
     8    const outlets = groups.reduce((outlets, group) => {
     9      return outlets.concat(group.outlets);
    10    }, []);
    11  
    12    const intervals = outlets.reduce((intervals, outlet) => {
    13      return intervals.concat(outlet.schedule);
    14    }, []);
    15  
    16    const value = { groups, outlets, intervals };
    17  
    18    return (
    19      <Context.Provider value={value} {...rest}>
    20        {children}
    21      </Context.Provider>
    22    );
    23  }