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

React Native setState issue using an Object with TypeScript

$
0
0

I am having trouble with the setState of objects.My interface definition is as follows;

export interface IProjectData {  Id?: string,  Description?: string,  ProjectState?: string,}

I access the parameter I sent with RootStackParamList as follows.

function ProjectScreen({ route, navigation }: ProjectProps) {  const [project, setProject] = useState<IProjeData>(null)  useEffect(() => {    const sProject = JSON.stringify(route.params.project)    let myProject: IProjeData = JSON.parse(sProject)    console.log('myProject: ')    console.log(myProject)    setProject(myProject)    console.log('Project: ')    console.log(project)  }, [])  return (    ...    ...  )}

Consol output is as follows. Where am I going wrong? Why can't I assign a value to project?

myProject: {Id: "bd7acbea", Description"My Test Project", ProjectState"25/25"}Project: null

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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