Issue
Hi everybody im making a new app at react native using tsx and i have a question.
Im have three props at screen, one boolean and two functions, my question is there is a way of to define a proptype function without to use "any" type? using js with "proptypes" i can to use proptypes "function" but i do not have idea of how to make this using typescript
import React from 'react'
import { View, StyleSheet, Text, Modal, TouchableOpacity } from 'react-native';
import { RNCamera } from 'react-native-camera';
interface propTypes {
isVisible : boolean,
scanCallback: any,
OnCloseModal: any
}
const ScannerModal = ({isVisible, scanCallback, OnCloseModal}: propTypes) => {
if (!isVisible) {
return null
}
const onBarCodeRead = (e : {data : string, type: string}) => {
scanCallback(e.data, e.type)
}
return (
.....
)
}
Solution
Yes, you can do something like
interface propTypes {
isVisible : boolean,
scanCallback: (_data: string, _type: string) => void,
OnCloseModal: () => void
}
Here is a helpful guide on using typescript in react. It also applies to react-native.
Answered By - Moistbobo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.