score:0
you should add optional chaining when using map "?". add it after data.
{data?.executive.length > 0 ? (
data?.executive.map((exec) => {
score:0
you inited your data
in the wrong way. that was not an array. change into this
const [data, setdata] = usestate(null); ... if(!data) return null; // you can handle the loading page here when data is not ready yet return ( ... )
score:0
[]
in typescript is automatically inferred as never[]
:
const [data, setdata] = usestate([]); // usestate<never[]>([]);
// ^^ never[]
so you have to tell typescript that it's not (and thankfully usestate accepts a generic):
const [data, setdata] = usestate<{ post_id: number; post_title: string }>([]); // good
but for readability too, use an interface:
interface postdata { post_id: number; post_title: string }
const [data, setdata] = usestate<postdata[]>([]);
score:0
if you are expecting an object according of the api response, you need to initialize the usestate({}) with an empty object instead of an array
const [data, setdata] = usestate({});
then you'll have to check if the object has the properties you are expecting in this line:
<ionlabel>{data?.aboutdata?.post_title}</ionlabel>
you can use optional chaining for this part. and also for this line, take care of the properties
{data?.executive?.length > 0 ? (
depends on what your trying to do, i'd recommend you to paint the list conditionally depending on the data content.
Source: stackoverflow.com
Related Query
- Property 'value' does not exist on type 'Readonly<{}>'
- TypeScript error: Property 'X' does not exist on type 'Window'
- typescript + react/redux: property "yyy" does not exist on type 'intrinsicattributes & intrinsicclassattributes
- Typescript complains Property does not exist on type 'JSX.IntrinsicElements' when using React.createClass?
- error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'
- TypeScript error after upgrading version 4 useParams () from react-router-dom Property 'sumParams' does not exist on type '{}'
- Property 'exact' does not exist on type
- Property 'toBeInTheDocument' does not exist on type 'Matchers<any>'
- Trigger click in Typescript - Property 'click' does not exist on type 'Element'
- Property does not exist on type 'DetailedHTMLProps, HTMLDivElement>' with React 16
- TS2339: Property 'tsReducer' does not exist on type 'DefaultRootState'
- Property ... does not exist on type 'IntrinsicAttributes & ...'
- Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'
- Property 'hot' does not exist on type 'NodeModule'.ts(2339)
- TS2339: Property 'props' does not exist on type 'Home'
- TypeScript error: Property 'children' does not exist on type 'ReactNode'
- TypeScript error: Property 'scrollIntoView' does not exist on type 'never'. TS2339
- Property 'value' does not exist on type 'never'. when use useRef hook in mui
- ts(2322) Property children does not exist on type 'Intrinsic attributes and Props'
- Property does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'
- Generics error with forwardRef: Property 'ref' does not exist on type 'IntrinsicAttributes'
- Property 'current' does not exist on type '((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement>'
- In ReactJS trying to get params but I get property 'id' does not exist on type '{}'
- Property "value" does not exist on type Readonly
- Typescript Error: TS2339: Property 'span' does not exist on type 'JSX.IntrinsicElements'
- ReactJS TS, Property 'match' does not exist on type 'Readonly<{children?:ReactNode}> & Readonly<MyProps>'
- useRef Typescript error: Property 'current' does not exist on type 'HTMLElement'
- React with Typescript: Property 'push' does not exist on type 'History'
- Property 'state' does not exist on type 'FetchPeriod'
- Property 'y' does not exist on type 'DefaultRootState'
More Query from same tag
- reading firebase database with an onCreate()
- How to render different components based off device size?
- Can't understand how passing function to update state hook works
- Correctly use useState variable
- How to filter and sort the same table data with React?
- Difficulty installing Google Tag Manager in React for Google Analytics
- How to compile imported ES6 node modules?
- How to use setInterval inside useEffect to update the state?
- How to limit props.children.some to image type only?
- Property 'item' does not exist on type 'IntrinsicAttributes & { name: string; href: string; }'
- Prevent re-rendering unchanged items in todo app with React Context and useReducer
- How to get all the data with Promise.all in the useEffect hook?
- How do I make a client-side only component for GatsbyJS?
- how does mobx achieve its magic
- React-select - can't stopPropagation on valueRenderer component
- How to prevent Header from rendering on Login screen?
- I am having hard time writing Jest test for timer
- How to read variable from JS file present in root folder in a React Component?
- React + Jest Testing Error - ReferenceError: expect is not defined
- Display items from JSON server response
- React/Typescript conditional routing - Updating from React Router Dom v5 to v6
- React-Native Headless doubts
- How to use animation every time image changes with react-spring?
- Convert nested json object into another json object
- ReactDOMServer is not defined
- Draft.js Inserting Immutable Entity
- How to redirect after Nodemailer POST request
- Passing values to a nested component in Storybook
- array.filter not returning nested array of parent array in reactjs
- Accessing a website deployed in a virtual machine from local server outside the network