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

Initializing redux state type checking with Typescript on component level

$
0
0

I coding React Native application using RTK Query with Typescript for state management, I have main slice which holds 3 depth level company object itself and other things like loading state etc. If user login successfully ,I am fetching the company info from remote and dispatching to the main slice store as currentCompany. So user can not use application without a company. But when i initializing the redux store.Initial state like:

interface MainSlice {  loading: number;  isLoggedIn: boolean;  currentCompany: Company | undefined; #If I use only company here I have to give dummy company for initial state which is not good practice.}const initialState: MainSlice = {  loading: 0,  isLoggedIn: false,  currentCompany: undefined, #As I mentioned I had to define current company as undefined. If a define a dummy Company here because of company type requires a lot attributes I don't want to do that.};

When I use the main slice like that I always had to check at component level If company is undefined or not. So this is exhausting.Typescript error ss

Is there any way to escape from Typescript error or proper initial state for this situation.I want to define company as will be certainly existed


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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