AuthContext.tsx
import createDataContext from './createDataContext';import serverApi from '../api/server';const authReducer = ({state, action}: any) => { switch(action.type){ default: return state; }};const signup = () => { return async ({email, password}: any) => { try{ const response = await serverApi.post('/signup', {email, password}); console.log(response.data) }catch(err){ console.log(err.message); } };}const signin = ({dispatch}:any) => { return ({email, password}: any) => { };}const signout = ({dispatch}: any) => { return () => {};}export const {Provider, Context} = createDataContext( authReducer, {signin, signout, signup}, {isSignedIn: false});
createDataContext
import React, { useReducer } from 'react';export default ({reducer, actions, defaultValue}: any) => { const Context = React.createContext(); const Provider = ({ children }: any) => { const [state, dispatch] = useReducer(reducer, defaultValue); const boundActions: any = {}; for (let key in actions) { boundActions[key] = actions[key](dispatch); } return (<Context.Provider value={{ state, ...boundActions }}> {children}</Context.Provider> ); }; return { Context, Provider };}
I copy the code from a video tutorial where react native app has been developed with js extension. But the project I am working on has tsx extension i.e. TypeScript.How to convert the above code so it will work in my typescript react native mobile app?