I am new in React and I am Developing simple CRUD application in React with the help of Hooks.
The app has two form components AddUserForm
and EditUserForm
which add and edit users list corespondingly. Also there is a component which displays the list of users (but I have not got warnings there).
Everything works fine but I have the following warning message in my browser's console:
Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
.
Here is how I render child components in my App.js file. (I marked the lines where I have warnings with red arrows)
Update
Here is how I handle form in AddUserForm
component:
return (
<Fragment>
<form> // line 15, here I have warning as well
onSubmit=
{event => {
event.preventDefault();
if (!user.name || !user.username) return;
props.addUser(user);
setUser(initialFormState);
}}
<label>Name</label>
<input type='text' name='name' value='' onChange={handleInputChange} />
<label>Username</label>
<input
type='text'
name='username'
value=''
onChange={handleInputChange}
/>
<button>Add new user</button>
</form>
</Fragment>
);
I have checked some solutions that are written for example here but none of them were helpfull for this issue.
Could you give me any hint of what I am doing wrong?