Home > Enterprise >  react native typescript why I get 2x is_verified object ? How can I get only 1x
react native typescript why I get 2x is_verified object ? How can I get only 1x

Time:10-24

I have a interface named user

export interface CurrentUser {
  user_id: number;
  is_verified?: boolean;
}

So then I want to add a verified component.

import { StyleSheet, Text, View } from 'react-native'
import React from 'react'
import { CurrentUser } from '../../store/slice/Auth/Auth';

const Verified = (is_verified: Pick<CurrentUser, 'is_verified'>) => {

  return (
    <View>
      <Text>Verified</Text>
    </View>
  )
}

const styles = StyleSheet.create({

});

export default Verified;

The problem is now I can access 2x is_verified like this:

is_verified.is_verified

How can I make it only one time ?

CodePudding user response:

Try this instead:

const Verified = ({ is_verified }: CurrentUser>) => {

Explanation:

Functional components are called with the props object as the first argument. My version destructures the named prop out of the props object. Since your version doesn't do this, the whole object is called is_verified, which is why you have to access the prop you want from that object.

  • Related