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

React native with typescript passing useState as props

$
0
0

I have responsive.tsx file and I want to take an useState hook as props that contains orientation mode for app from app.tsx. I have an issue with types.

Argument of type 'Dispatch<SetStateAction>' is not assignable to parameter of type 'Props'. Property 'setOrientation' is missing in type 'Dispatch<SetStateAction>' but required in type 'Props

 //in responsive.tsxtype OrientationProp = {    orientation:string}type Dispatcher<S> = Dispatch<SetStateAction<S>>;type Props = {    setOrientation : Dispatcher<any>}const listenOrientationChange = ({ setOrientation  }:Props) => {  Dimensions.addEventListener("change", (newDimensions) => {    // Retrieve and save new dimensions    screenWidth = newDimensions.window.width;    screenHeight = newDimensions.window.height;    // Trigger screen's rerender with a state update of the orientation variable  });  let orientation:OrientationProp = {    orientation: screenWidth < screenHeight ? "portrait" : "landscape",  };  setOrientation(orientation);};//in app.tsx    const [orientation,setOrientation] = useState(null);      useEffect(() => {        listenOrientationChange(setOrientation) // the error is here //Argument of type 'Dispatch<SetStateAction<null>>' is not assignable to parameter of type 'Props'. Property 'setOrientation' is missing in type 'Dispatch<SetStateAction<null>>' but required in type 'Props'      },[])

Viewing all articles
Browse latest Browse all 6214

Trending Articles



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