score:1
You need to provide the typings for your Today
component. From what I can see, the Today
component accepts dailyObd
as the props, so you will need to create an interface or type genetic for the component.
In addition, you might want to rename your dailyObd
interface to use upper camelcase instead, as this is one of the naming conventions for classes/interfaces.
interface DailyObd {
title: string;
completed: boolean;
}
Now, you can provide the generic type parameter for Today
.
interface TodayProps {
dailyObd: DailyObd[];
}
const Today: React.FC<TodayProps> = ({ dailyObd }) => { ... }
score:0
I seem to have resolved the next issue which popped up after I applied typing to the Today component as wentjun suggested. Following the comments on wentjun's answer, I eventually found that in the route's render prop, the variable passed into the anonymous function is not the state variable that I had created, despite it sharing the same name. When I removed that variable from the anonymous function declaration, I found that the state variable that I created was then being passed into the Today component as it was created and the application is working as expected now. Here's the TS I settled on:
App.tsx:
const App: React.FC = () => {
const [dailyObds, setDailyObds] = useState<DailyObd[]>([{
title: 'first',
completed: false
},{
title: 'second',
completed: true
}])
return (
<IonApp>
<IonReactRouter>
<IonSplitPane contentId="main">
<Menu />
<IonRouterOutlet id="main">
<Route path="/page/today" render={()=>(<Today dailyObdsProp={dailyObds} /> )} />
<Redirect from="/" to="/page/Inbox" exact />
</IonRouterOutlet>
</IonSplitPane>
</IonReactRouter>
</IonApp>
)
}
interface DailyObd{
title: string
completed: boolean
}
export default App
Today.tsx:
const Today: React.FC<Today> = (dailyObdsProp)=>{
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonButtons slot="start"><IonMenuButton /></IonButtons>
<IonTitle>Today's Obds</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonText>
{
dailyObdsProp.dailyObdsProp.map(
obd=>(
<p>{obd.title} - {obd.completed ? 'Completed' : 'Uncomplete'}</p>
)
)
}
</IonText>
</IonContent>
</IonPage>
)
}
interface Today{
dailyObdsProp: DailyObd[]
}
interface DailyObd{
title: string
completed: boolean
}
export default Today
Thanks everyone for your help! Please let me know if there's an issue with this solution.
Source: stackoverflow.com
Related Query
- Getting TypeScript compile error when attempting prop drilling of state objects in Ionic/React
- Getting error when destructure value from state in TypeScript
- Getting typescript error when pushing object into state array with useState
- CSS Emotion Library - Getting css props error when using css prop
- Getting error when creating React HOC in Typescript
- Objects are not valid as a React child getting error when adding div?
- I am getting state undefined error when reloading page
- Getting an error message when I filter the redux state
- Error coming when using the state value in react using typescript
- Getting an error when trying to trigger a function for state change
- When I am trying to import a custom hook function I am getting a typescript error
- Getting "No overload matches this call" error when using useQuery with TypeScript
- I am not able to add user input to state properly, getting map not a function error when it is
- Typescript error showing up when update method for state element by using React useState
- Getting CORS error in ReactJS app when attempting to execute localhost API
- Getting "Warning: setState(...): Can only update a mounted or mounting component." error when setting state inside "FB.Event.subscribe()" function
- React Typescript trying to change state of an array objects resulting in error
- Getting error `Type '{ theme: Theme; }' is not assignable to type` when trying to pass it as a prop to App component
- Getting the Error when I get selectors from createEntityAdapter in Typescript
- Getting TypeError: Object(...) is not a function error when trying to change a state property
- Why am I getting error “hook cannot be called inside a callback” when setting state in React?
- cryptic TypeScript error message when not returning the state from a reducer
- Attempting to compile this code simply wont work. Getting a parsing error from react.js and vscode
- Getting property of type doesn't exist error when using TypeScript
- Getting this error when replying to comment: Can't perform a React state update on an unmounted component
- TypeScript doesn't catch error with incorrect interface props when setting state - React
- I am new in typescript When I compile my code given No overload matches this call error
- TypeScript React onChanged: getting an error when trying to execute the web part in sharepoint
- React.js when using non state variable Getting error as A component is changing an uncontrolled input of type text to be controlled
- Error when updating state with useState + TypeScript
More Query from same tag
- How to unit test jquery being called with Jest and Enzyme?
- re-render GoogleMapReact
- How to set only one property in object with useState?
- How can i search for keywords in a javascript array?
- how to fix "failed to compile" in reactjs?
- Is it a good practice to create base components and then extend them in React?
- Conditional API call using Axios with React Hooks
- Could not run adb reverse (React-Native)
- Cannot conditional render in render method react js
- React UI not re-rendering on click even though DB is updated correctly. After second click, UI re-renders
- TypeError: Cannot set property 'usingClientEntryPoint' of undefined
- react and express app not allowing jsx
- React : best way to inject Component in dynamically loaded HTML?
- How to toggle a content of the single element in React JS?
- How to get the chips inside the input box?
- Create a hierarchy list from an JSON based on some key values JavaScript
- Import library only if document is present (not on server)
- React set styles on Body
- What does calling super() in a React constructor do?
- how to get callback from child to parent class in react-redux?
- How to detect mobile device with NextJS
- React Facebook Login - Hide Button after Login
- I'm trying to pack several files into an array, but only one is shown at a time
- Material UI Popover - keydown event simulation issue
- Export React component with two property
- ReactJS dynamic pages from mongodb
- Multiple functions inside onClick with a ternary and reference
- React: How can I call a method only once in the lifecycle of a component, as soon as data.loading is false
- Must React components act like pure functions with respect to their props?
- Update context when state object mutates