Using Store & createContext

by Admin 27. January 2020 09:58

store.tsx

import React from "react";

const initialState = {};
export const Store = React.createContext(initialState);

function reducer() {
//todo
}

export function StoreProvider(props: any) {
return <Store.Providervalue="test">{props.children}</Store.Provider>;
}

index.tsx

import React from "react";
import ReactDOM from "react-dom";
import { StoreProvider } from "./store";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(
<StoreProvider>
<App/>
</StoreProvider>,
rootElement
);

 

App.tsx

import React, { Fragment } from "react";
import "./styles.css";
import { Store } from "./store";
//const { Provider, Consumer } = React.createContext();

function App(): JSX.Element {
const store = React.createContext(Store);

return (
<Fragment>
{console.log(store)}
<h1>Ricky And Venkat</h1>
<p>Pick your episode</p>
</Fragment>
);
}

export default App;

 

 

Tags:

Comments are closed

TextBox

Tag cloud

    RecentPosts