i'm new to React and i'm creating a form following a internet tutorial, but just in the start i've run into this error: Syntax error: Unexpected token, expected "{" (8:16)
This is my code:
import React from 'react';
import './App.css';
import Form from './components/Form.js';
const handleSubmit = values => alert(JSON.stringify(values));
const initialValues = {}
function App() =>(
<div>
<Form handleSubmit={handleSubmit} initialValues={initialValues} />
</div>
)
export default App;
Your function should be an arrow function:
const App = () => (
<div>
<Form handleSubmit={handleSubmit} initialValues={initialValues} />
</div>
);
or a normal function with a return:
function App() {
return (
<div>
<Form handleSubmit={handleSubmit} initialValues={initialValues} />
</div>
);
}
More about functions here.
Additional you can pass the brackets comes after App if function has one parameter.
const App = parameterA => (
<div>
<Form handleSubmit={handleSubmit} initialValues={initialValues} />
</div>
);