Open untitledlt opened 5 years ago
Can you show is the <Router>
part? The error message suggests that thecreateContext
API is used and one of the consumers has an invalid child. Check if all consumers are similar to this example:
<Consumer>
{value => <MyComponent foo={value} />}
</Consumer>
It's the same as per preatc-router examples. I do not use context, but i use redux which uses context internally. Redux provider wraps higher
<Router>
<Home path="/" />
<Profile path="/profile" />
</Router>
I'm asking because the chance that this is an issue with preact-router
is very unlikely because it doesn't even use context at all. Can you share a codesandbox or a repo where the issue can be reproduced? We'd love to take a look at it 👍
@Ucorp That's a different issue :slightly_smiling_face: The way preact-router
currently works is that it expects direct children of the Router
component to have a path="/foo"
prop. It will fail if that's not present.
Change this:
<Router>
<ThemeContext.Provider value={{ theme, setTheme }}>
<Home path="/" />
<About path="/about" />
<button onClick={() => setTheme("dark")}>set dark</button>
<button onClick={() => setTheme("light")}>set light</button>
</ThemeContext.Provider>
</Router>
...to this:
<ThemeContext.Provider value={{ theme, setTheme }}>
<Router>
<Home path="/" />
<About path="/about" />
</Router>
<button onClick={() => setTheme("dark")}>set dark</button>
<button onClick={() => setTheme("light")}>set light</button>
</ThemeContext.Provider>
Oh sorry, thought that was the original issue
With PreactX I'm getting:
preact.module.js:14 Uncaught TypeError: Cannot read property 'default' of undefined
on my setup attributes
is not available, instead I see props
containing the path
@cristianszwarc make sure you're using preact-router@next
. It will be promoted to latest
once Preact X is released
cheers! preact-router@next
did the trick, works perfectly.
Hey I see that Preact X went live. Can this be merged?
Yep, we'll release a new stable version of preact-router
soon
I am still getting issue with preact-router only with the prod build. It says
TypeError: Object(...) is not a function
method: render at: <project_dir>/node_modules/preact-router/dist/preact-router.es.js
I am using
"preact": "^10.0.0",
"preact-router": "^3.0.1",
Any news on this? I am getting when clicking a link:
Uncaught (in promise) TypeError: Cannot read property 'type' of undefined
@vimtor this issue only happens when using a version of preact-router
that is out of date - just updating to version 3
fixes it.
I'm using latest
preact@10.0.0-beta.3
andpreact-router@3.0.0
. I'm getting no errors if i comment out<Router>...</Router>
part so I guess it'spreact-router
related.