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!
Source: stackoverflow.com
Related Query
- Objects are not valid as a React child -> Build time error -> next js typescript
- Objects are not valid as a React child Error in next js
- React Typescript - Error Objects are not valid as a React child
- Objects are not valid as a React child getting error when adding div?
- Handling error in React with Formik: Objects are not valid as a React child
- Error Objects are not valid as a React child (found: Invalid date)
- React error saying Objects are not valid as react child
- Objects are not valid as a React child error when giving value to react-select
- React setState error -> Objects are not valid as a React child
- React Objects are not valid as a React child error
- Error in map function / Objects are not valid as a React child / React.js
- react map returned error of Objects are not valid as a React child
- Objects are not valid as a React child error in React Datatable
- Objects are not valid as a React child - Confusing Error
- Getting Error Like Objects are not valid as a React child In ReactJs
- React Axios fetch response with error Objects are not valid as a React child
- I AM HAVING ERROR WHEN TRYING TO MAP A DATA IN REACT . Objects are not valid as a React child (found: object with keys {children}), How do i solve it?
- What is causing this error - Objects are not valid as a React child (found: object with keys {id, task})
- Getting error Objects are not valid as a React child
- Objects are not valid as a React child with state while rendering error
- REact error Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead
- Getting a Objects are not valid as a React child error even though I am not trying to render an object
- Trying to add an array of objects using react useState but getting the error 'Objects are not valid as a React child (found: object with keys {})'
- Handling error Objects are not valid as a React child
- Passing an array of object to useState throws this error Objects are not valid as a React child (found: object with keys {id, name})
- Build a string and use it as an html object: Uncaught Error: Objects are not valid as a React child
- getting error about objects are not valid as a React child
- Objects are not valid as a React child error in Datatable
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. error
- Objects are not valid as a React child - Cannot resolve error
More Query from same tag
- Best way to develop this function in react js instead of this current .map
- How can I change a certain attribute in a certain object with React Hooks?
- Deck.GL ScatterplotLayer does not render points
- handle the event on click and toggle the button color on react webchat
- How to check whether a property supplied to React component is an instance of Immutable.js Record with Flow?
- Login with Google custom email only
- how to add dynamic content inside a textarea tag using map method
- Blob to base64 ReactJs
- Classes on tab key press not being added and removed correctly
- Unit Testing Jest in Reactjs Component state
- Move content left and right to follow Drawer open / close (Material-UI)
- Organizing array of objects using specific object's field value
- on button return id to show specific json react js
- React hooks: accessing up-to-date state from within a callback
- Cypress check if one element has a certain text value
- Minify/Mangle CSS Classnames in JSX and CSS output from Webpack (or other programmatic means)
- Material UI Paper element not covering 100% of viewport height
- Porting WordPress Gutenberg to a Standalone React Component - CSS Styles Not Appearing
- how to assign variables to an object for submitting the Data using reactjs?
- React Component fade in fade out transition by switching of state?
- Need to have the user be able to edit profile with an edit button
- Targeting a specific child of this.props.children
- How to make autofocus on input field when using react-final-form?
- How to conditionally render a prop in TSX
- TypeError: #<Promise> is not iterable
- aggregate values from nested collection of JSON into React table
- React Select value is not resetting on State Change
- How would translate this react-router3 router to react-router4?
- React JSX class library exports are not working
- React Native - Jest: Broken since update to 0.56. How to fix it?