react context hook

    0

    0

    Estee Tey

    React Native Recipes

    if you need a way to update a custom context through a hook, this recipe will generate an example of how to write such a hook.

    import { createContext } from "react";
    
    export interface Tweet {
        id: string;
        content: string;
    }
    export interface TweetContext {
        tweets: Tweet[],
        setCurrTweets: (tweets: Tweet[]) => void;
    }
    const defaultContext: TweetContext = {
        tweets: [],
        setCurrTweets: () => { },
    };
    const TweeterContext = createContext<TweetContext>(defaultContext);
    export default TweeterContext;
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.