Below are two versions of my code. When the context is not split into a separate file, the result is only value, working as expected. However when it is split, then the result is double as valuevalue. I can't reasoning why this is the case. Do you have any idea?
Case 1: Not splitting context to another file
routes/index.tsx
import { User } from "../../fresh-project/islands/User.tsx";
import { createContext } from 'preact'
export const Username = createContext()
function ContextProvider({children}) {
return (
<Username.Provider value="value">{children}</Username.Provider>
);
}
export default function App() {
return (
<ContextProvider>
<User />
</ContextProvider>
)
}
islands/User.tsx
import { useContext } from 'preact/hooks';
import { Username } from '../routes/index.tsx'
export function User() {
const username = useContext(Username);
return <>{username}</>;
}
The result of this is value.
Case 2: Splitting context to another file
routes/index.tsx
import ContextProvider from '../islands/Context.tsx'
import { User } from "../../fresh-project/islands/User.tsx";
export default function App() {
return (
<ContextProvider>
A<User />a
</ContextProvider>
)
}
Below are two versions of my code. When the context is not split into a separate file, the result is only
value
, working as expected. However when it is split, then the result is double asvaluevalue
. I can't reasoning why this is the case. Do you have any idea?Case 1: Not splitting context to another file
routes/index.tsx
islands/User.tsx
The result of this is
value
.Case 2: Splitting context to another file
routes/index.tsx
islands/Context.tsx
islands/User.tsx
Then at first the result is
Avaluea
as expected, but quickly rendered toAvalueavaluea
.Case 3: Adding a character after
{children}
onContext.tsx
Then at first the result is
Avaluea
as expected, but quickly rendered toAvalueacac
.