Advertisement
robertvari

Context example

Aug 5th, 2020
1,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {createContext, useState} from "react";
  2.  
  3. export const CutContext = createContext(true);
  4.  
  5. export const CutProvider = (props) => {
  6.     const [current_index, set_current_index] = useState(0)
  7.     const [cut_list, set_cut_list] = useState([])
  8.  
  9.     return (
  10.         <CutContext.Provider
  11.             value={
  12.                 {
  13.                     current_index: current_index,
  14.                     set_current_index: set_current_index,
  15.  
  16.                     cut_list: cut_list,
  17.                     set_cut_list: set_cut_list
  18.                 }
  19.             }
  20.         >
  21.             {props.children}
  22.         </CutContext.Provider>
  23.     )
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement