DEV Community

Ekim Kael
Ekim Kael

Posted on

How do you handle a component update ?

i'm working on my portfolio using a React cousin Preact. Component lifecycle are the same and i want to update the route that display details about a project when clicking on another project and i'm lost😅.can you please help me?

Top comments (6)

Collapse
 
andy profile image
Andy Zhao (he/him)

I believe the lifecycle methods are the same for Preact. In general, you should be able to setState and that should update your component.

For routes, maybe the Preact router readme will help? github.com/developit/preact-router

Collapse
 
pichardoj profile image
J. Pichardo

Can you share any code? In order to see what you have.

Collapse
 
ekimkael profile image
Ekim Kael

You Can check thé demo here: for example
By trying to click another projects on the side.
I'll show some codes when i'll bé on my PC

Collapse
 
gaserd profile image
Sergey Gustun
Collapse
 
ben profile image
Ben Halpern

If this is specifically about the router portion, are you missing something like this?

developit / preact-router

:earth_americas: URL router for Preact.

preact-router

NPM travis-ci

Connect your Preact components up to that address bar.

preact-router provides a <Router /> component that conditionally renders its children when the URL matches their path. It also automatically wires up <a /> elements to the router.

💁 Note: This is not a preact-compatible version of React Router. preact-router is a simple URL wiring and does no orchestration for you.

If you're looking for more complex solutions like nested routes and view composition, react-router works great with preact as long as you alias in preact-compat. React Router 4 even works directly with Preact, no compatibility layer needed!

See a Real-world Example ➡️


Usage Example

import Router from 'preact-router'
import { h, render } from 'preact'
/** @jsx h */
const Main = () => (
    <Router>
        <Home path="/" />
        <About
Collapse
 
ekimkael profile image
Ekim Kael

I'd already check and use or.the problem is n'ont coming from the router.
Route work well.please if you Can check this and try to it something in ##other project## on the right side