onSubmit have to be used on form element. MDN: Form
When you change this, your context will get updated. There is still one more problem though but once you see the value of the context you should be able to figure it out
The site refreshes because that’s the default behaviour when submitting the form. That’s why we use event.preventDefault().
In your code however even though there is event.preventDefault() it still refreshes when submitting the form. It most likely means that handleSubmit was not called. The reason it was not called is because onSubmit doesn’t work on button elements but instead have to be used on form element.
Once you fix this, the site shouldn’t refresh anymore.
Let’s leave JSON, because it has nothing to do with it
You’re trying to access length property and then use map method so you need todo to be an array not an object.
And actually you even initialized your todo to be an empty array here:
const [todo, setTodo] = useState([]);
So somewhere in the process you changed that array to be an object. You’ll have to find where.
PS I think it would be reasonable to rename todo to todos if you want to store multiple items. It’s not obligatory but I think it’d be more readable and easier to debug.