I need to set data from the backend to an object using react hook. The data from the backend cannot be the same structure always, so need to treat that as an Anonymous Object.
import axios from "axios";
function AppNew() {
const [anonymousObject, setAnonymousObject] = useState({});
useEffect(() => {
const fetchData = async () => {
const result = await axios("https://example.com/GetData");
setAnonymousObject(result.data);
};
fetchData();
}, []);
return <div> {anonymousObject} </div>;
}
export default AppNew;
It ends up with the error
Uncaught Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead. react-dom.development.js:13231
Any idea how to handle this?