React hooks won't work in free workspace

Anybody knows why this code is not working? I don’t have any problems to execute the react hooks in the exercises, but here, every time I try to put this line:
const [test, setTest] = useState();
my code stop running.

as far as I know, you can’t mix class based components (app.js) and functional components (test.js). In which exercise did you do that, can you link the lesson?

1 Like

thanks for answer me. But same doing that:

import React, { useState } from ‘react’;

import ReactDOM from ‘react-dom’;

export default function App() {

const [test, setTest] = useState();

return (

<h1>Hello world</h1>







the code doesn’t run as long as I keep this line:
const [test, setTest] = useState();

Not sure if that is just bad practice or the reason why your app crashes:
You should initialize your state hook like

const [test, setTest] = useState('');
const [test, setTest] = useState({});
const [test, setTest] = useState(null);
const [test, setTest] = useState([]); // whatever data type will be set

Please format your code following this guide:

1 Like

i know that. In the exercises my code always executes normal, I don’t know what’s going on, maybe it’s not my fault. Thanks for try to help me. :slight_smile:

1 Like