const PostScreen = ({ navigation }) => { const route = useRoute(); const [title,…
- User
const PostScreen = ({ navigation }) => { const route = useRoute(); const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [location, setLocation] = useState(null); const [tags, setTags] = useState([]);
// Route doesn't become available until rendered apparently useEffect(() => { const location = route.params?.location; if(location) { setLocation([location.latitude, location.longitude]); } }, [route.params?.location]);
I'm getting Property 'location' does not exist on type 'object'.ts(2339)
- Assistant
The error you're encountering,
Property 'location' does not exist on type 'object'.ts(2339), indicates that TypeScript does not recognize thelocationproperty within theroute.paramsobject because the type definition forroute.paramsdoes not include it.To resolve this, you need to explicitly define the type for and its property. Here’s how you can do that: