Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Cannot invoke an object which is possibly 'null' context

$
0
0

why I get this ts error:

Cannot invoke an object which is possibly 'null'.

Context.tsx

import React, { createContext, useState } from 'react';type ForgotPasswordProviderProps = {  children: React.ReactNode;}export type Email = {  email: string | null;  setEmail: React.Dispatch<React.SetStateAction<string>> | null;}export const ForgotPasswordContext = createContext<Email | null>(null);export const ForgotPasswordContextProvider = ({  children}: ForgotPasswordProviderProps) => {  const [email, setEmail] = useState('');  return <ForgotPasswordContext.Provider value={{email, setEmail}}>{children}</ForgotPasswordContext.Provider>}

ForgotPassword.tsx

  const handleChangeEmail = (e: string) => (emailContext && emailContext.setEmail('asas');

this error comes on line: emailContext.setEmail

How can I solve this issue ?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>