score:0

If you are trying to return the object as a component you need to first stringify the object or transform it from an object type. Objects are not valid JSX/React elements.

You can do:

type objType = {
  name: string
  age: number
}

const obj: objType = {
    name: "A",
    age: 20
}

function ObjFileReturn() {
  return <div>{JSON.stringify(obj, null, '\t'}</div>

export default ObjFileReturn;

JSON.stringify() converts the object to string which you can use inside a div to return from the functional comonent. The extra parameters in strigify pretty-print it so that it remains formatted.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Hope that helps!


Related Query

More Query from same tag