ahhzaky / google-clone

This is a Google-Clone with API Google Search and this app responsive.
MIT License
1 stars 0 forks source link

StateProvider #4

Open ahhzaky opened 3 years ago

ahhzaky commented 3 years ago

Preparing the data layer

import React, { createContext, useContext, useReducer } from "react";

export const StateContext = createContext();

export const StateProvider = ({ reducer, initialState, children }) => (
  <StateContext.Provider value={useReducer(reducer, initialState)}>
    {children}
  </StateContext.Provider>
);

export const useStateValue = () => useContext(StateContext);

this is needed to wrap the data layer.

ahhzaky commented 3 years ago

untuk memasuki app dibungkus dengan stateprovider supaya setelah melewati dua hal yaitu reducer dan initialState maka app bisa di akses.

initnya stateprovider untuk membungkus data.

ahhzaky commented 3 years ago

export const useStateValue = () => useContext(StateContext);

this is Hook which allows us to pull information from the data layer.

ahhzaky commented 3 years ago

More information about Redux

https://redux.js.org/

ahhzaky commented 3 years ago

meng-import StateProvider:

import{ StateProvider }from "./StateProvider";