Here is my code:
JavaScript
x
24
24
1
return (
2
<ThemeProvider theme={props.theme}>
3
4
<section className={classes.loginForm}>
5
{
6
mode === "LOGIN"
7
?
8
<LoginForm theme={props.theme} />
9
<br/> <br/>
10
<Button variant="contained" color="primary" onClick={() => setMode("SIGNUP")}>
11
SIGNUP?
12
</Button>
13
:
14
<SignUpForm theme={props.theme} />
15
<br/><br/>
16
<Button variant="contained" color="primary" onClick={() => setMode("SIGNUP")}>
17
SIGNUP?
18
</Button>
19
}
20
</section>
21
22
</ThemeProvider>
23
);
24
The error appears at the first character of the opening tag for the breakline HTML element. I do not understand why this is happening as I have code elsewhere that uses the same principle and has no errors at all.
Advertisement
Answer
These elements, inside the curly braces, need to be wrapped inside of a <React.Fragment />
(<>
and </>
for short)
https://reactjs.org/docs/fragments.html
Your code:
JavaScript
1
16
16
1
{
2
mode === "LOGIN"
3
?
4
<LoginForm theme={props.theme} />
5
<br/> <br/>
6
<Button variant="contained" color="primary" onClick={() => setMode("SIGNUP")}>
7
SIGNUP?
8
</Button>
9
:
10
<SignUpForm theme={props.theme} />
11
<br/><br/>
12
<Button variant="contained" color="primary" onClick={() => setMode("SIGNUP")}>
13
SIGNUP?
14
</Button>
15
}
16
Corrected code:
JavaScript
1
20
20
1
{
2
mode === "LOGIN"
3
?
4
<>
5
<LoginForm theme={props.theme} />
6
<br/> <br/>
7
<Button variant="contained" color="primary" onClick={() => setMode("SIGNUP")}>
8
SIGNUP?
9
</Button>
10
</>
11
:
12
<>
13
<SignUpForm theme={props.theme} />
14
<br/><br/>
15
<Button variant="contained" color="primary" onClick={() => setMode("SIGNUP")}>
16
SIGNUP?
17
</Button>
18
</>
19
}
20