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.


Related Query

More Query from same tag