I develop in react-native using typescript. When passing parameters to a screen, I utilize the navigate
function.
this.props.navigation.navigate("NextScreen", { title: "title" })
On the NextScreen
component, I retrieve these params by accessing
this.props.navigation.state.params.title
, but I encounter a tslint error regarding params
.
TS2339:Property 'params' does not exist on type 'NavigationState'.
This snippet demonstrates some of the code:
import { NavigationInjectedProps } from "react-navigation";
interface OwnProps {
}
interface OwnState {
}
type Props = NavigationInjectedProps & OwnProps;
class NextScreen extends React.Component<Props, OwnState> {
...
public render() {
// The linting error occurs with this line.
const { title } = this.props.navigation.state.params;
...
}
}
I understand that defining the types for passed props is recommended, so what would be the best approach to do so?