Closed ooker777 closed 9 months ago
Never mind in User.tsx
I shouldn't put Username
as the argument for the component. The correct code should be:
import { Username } from '../routes/index.tsx'
export default function UsernameConsumer(){
return (
<Username.Consumer>
{username => (
<span>{username}</span>
)}
</Username.Consumer>
)
} ```
According to this comment, using context consumer instead of
useContext()
hook is workable. However I can only do that when they are in the same file. When splitting the consumer to another file I have the below result. I'm not sure if it's a bug or not, but it's similar to the case of splitting component overwrite the final result.routes/index.tsx
User.tsx
Log on terminal:
Log on the HTML