Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for A quick review of the Fresh web framework
Wumi4
Wumi4

Posted on

     

A quick review of the Fresh web framework

Unless you have been living under a rock, then you probably have heard ofFresh, the shiny new TypeScript web framework.

Fresh boasts some impressive features, such as:

  • No build step
  • No config needed
  • TypeScript support out of the box
  • No JavaScript is shipped to the client by default

But how good is Fresh in terms of developer experience?

To answer that question, I have built a simple file-system based pastebin service, calledPetunia, using Fresh and Deno.

Short answer?

Fresh is pretty good if you already know React and Tailwind, though it has some quirks that you have to get used to, like handling input.

The longer answer?

Fresh relies onPreact--a lightweight version of React--to display components, so if you are a React developer, then Fresh should feel like home to you.

When initializing a new project, Fresh will also ask if you want to useTwind, which is a Tailwind-to-JS library. If you choose this option, then you will have the power of Tailwind without creating a config file or using PostCSS, which I thought is pretty cool.

Here are a few things to notice though:

  • Fresh usesNextJS's file-system based routing, so for exampleroutes/link/[id].ts becomes/link/:id in the web app.

  • The way Fresh handles form submission is very different from React. Instead of using states like React, Fresh takes advantage of the HTML<form> element, by getting form data from<form> when the user enters the form, then using a custom handler to process that data, and return that data to the front-end.

Here'san example on the Fresh documentation, implementing a search form that filters an array of names server-side:

/** @jsx h */import{h}from"preact";import{Handlers,PageProps}from"$fresh/server.ts";constNAMES=["Alice","Bob","Charlie","Dave","Eve","Frank"];interfaceData{results:string[];query:string;}exportconsthandler:Handlers<Data>={GET(req,ctx){consturl=newURL(req.url);constquery=url.searchParams.get("q")||"";constresults=NAMES.filter((name)=>name.includes(query));returnctx.render({results,query});},};exportdefaultfunctionPage({data}:PageProps<Data>){const{results,query}=data;return(<div><form><inputtype="text"name="q"value={query}/><buttontype="submit">Search</button></form><ul>{results.map((name)=><likey={name}>{name}</li>)}</ul></div>);}
Enter fullscreen modeExit fullscreen mode

Discuss on HN |Tweet this post


You can also read this post inmy blog.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
distil profile image
Charavner Louis
All tech developper. Not only front or back. Database and embedded also
  • Location
    France
  • Joined

No lib work with deno

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I build stuff every so often
  • Location
    Vietnam
  • Work
    Student
  • Joined

More fromWumi4

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp