DEV Community

Cover image for React is awesome but have you tried fresh?

React is awesome but have you tried fresh?

ashish on June 30, 2022

Why Fresh? Let me start by asking you a simple question -- "Have you used react?" or have you used any JS framework or library for creat...
Collapse
 
dao profile image
Dao Shen • Edited

Kudos for using Deno! <3

React is not awesome. It encourages people to embed content and the structure for content in code. It looks like fresh is doing the same thing. No. For anything other than toys and one-offs, doing this results in brittle systems to maintain.

Reactive architecture however, now this is awesome. Really really awesome. Learn this from React and fresh, and then when we are done playing, we'll be ready for systems that both scale and can be maintained and grown over time.

All the best!

Collapse
 
asheeshh profile image
ashish

I agree with the second paragraph, couldn't have said it any better, but about the first paragraph - if you don't mind can you elaborate what do you mean by "embedding content in code", I think I'm missing something here.

Collapse
 
stealthmusic profile image
Jan Wedel

I think it’s about having logic, structure and styling in one file. I have never used react, but it always looked very weird to me. I agree with that in large applications, I would never ever want this. When I am changing code, I’ll do it in a ts file, when I change structure, I’ll do it in an html file and when I style something, I’ll do it in a css file. Very simple. That’s how browsers work and it’s a very sensible separation of concerns.

Thread Thread
 
asheeshh profile image
ashish

makes somewhat sense, though it's hard to structure your project when it's really big as most of the frameworks don't work the way you want them to and seeing how css-in-js is being used by more people, but I don't hate the way of structuring projects using folders like pages, components, styles too. It's not exactly what you want but is somewhat efficient and readable.

Thread Thread
 
imonem profile image
imonem

I think having everything in one file is for the purpose of the tutorial and not intended to be for scaling production. I use sass for larger projects. However if it's a quick prototype then it's bootstrap or two for the sake of speed

Thread Thread
 
asheeshh profile image
ashish

absolutely, I just wanted to show the basics of the framework, fresh is still very new to be used in production but I have high hopes from it.

Collapse
 
resetnak profile image
Alexandr Rešetňak

Just saw a video from Fireship about Fresh and there is already an article. Great community! Will definitely try Fresh. And well written article! Thanks.

Collapse
 
asheeshh profile image
ashish

thanks!

Collapse
 
n0n3br profile image
Rogério Luiz Aques de Amorim

I saw the documentation and wondered how can I share state between islands. I can't stick one island inside another island to pass the state by props. For me it seems a big downpoint for fresh. Hope they figure it out.

Collapse
 
asheeshh profile image
ashish

you can use non interactive "components" inside islands though, but not being able to call an island inside another is surely a thing I hope they work on.

Collapse
 
tqbit profile image
tq-bit

Fresh looks pretty cool. Out of curiousity: Could you find some tooling that helps with Deno imports? VSCode's intellisense alone doesn't cut it and shows me one error after the other when I try and fiddle around with Deno

Collapse
 
asheeshh profile image
ashish • Edited
  1. Install the official deno extension for vsc.

  2. create a .vscode folder in the project dir with settings.json file, put the following content inside it -

{
  "deno.enable": true,
  "deno.lint": true
}
Enter fullscreen mode Exit fullscreen mode

this is the basic config, you can learn more here.

  1. for finding packages, use deno.land/x
Collapse
 
bherbruck profile image
bherbruck

If you have docker installed, use the official deno devcontainer, it has everything set up

Collapse
 
yongchanghe profile image
Yongchang He

Thank you for sharing!

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
asheeshh profile image
ashish

I don't understand what you mean by "doesn't have a build", fresh does build the app, github.com/denoland/fresh/blob/mai...

about bundle size, I'm not really sure as I didn't check but it shouldn't be high according to me.

there are some benefits, being able to run the whole app on edge is a benefit in itself, not to mention all the benefits of using deno over node count in too, overall it's a great experience using fresh and I have a lot of expectations from this framework personally!

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
asheeshh profile image
ashish

its a relatively new tech, I'm currently trying to learn more about it myself so no need to worry 👍

Collapse
 
anthonybrown profile image
Tony Brown

Thanks for the write up. This looks like a cool framework

Collapse
 
n1ckdm profile image
Nick

Great article, thanks for sharing

Collapse
 
akshaw profile image
Ayush Kumar Shaw

Thanks for the post Ashish. Nice way of a starter introduction to Fresh. Once again, thanks.

Collapse
 
asheeshh profile image
ashish

thanks for reading!

Collapse
 
largenty profile image
Largenty

Can we use preact-router with it ?

Collapse
 
asheeshh profile image
ashish

again, I haven't tried it myself so I'm not sure, you can try asking in the issues though.
github.com/denoland/fresh/issues

Collapse
 
andrewbaisden profile image
Andrew Baisden

Cool, this is a new one for me.

Collapse
 
iamtahazzot profile image
Tahazzot • Edited

Fresh is old :) try Qwik js developed by Miško Hevery (Creator of AngularJS)

qwik.builder.io/

(Just kidding 😌) Use whatever you need :)

Collapse
 
airtonix profile image
Zenobius Jiricek

don't manually download engine binaries...

use asdf and asdf-deno, then drop a .tool-versions file in your project root

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

new terminal

asdf plugin add deno
asdf list-all deno
# note down the version you want
asdf install deno 1.32.0
asdf global deno 1.32.0
# makes 1.32.0 default for your user when not in a project
asdf local deno 1.32.0
cat .tool-versions
asdf reshim

asdf current
Enter fullscreen mode Exit fullscreen mode

When moving between projects, there's nothing to do. the ~/.asdf/shims/deno inspects your local .tool-versions

when pulling a project down, you should run asdf install when you see the .tool-versions file is modified.

I've now just taught you how to setup any other tool for your project and ensure that when you share the project or come back to it in (insert time frame where your brain turns to mush) minutes, you'll have added a degree of reproducability.

Collapse
 
funnypan profile image
panfan

how to import icons

Collapse
 
asheeshh profile image
ashish

As many npm modules dont yet support deno, things like react-icons may not work, though you can use simple-icons for sure with an image tag.

Other than that I'd personally prefer getting the svg paths of the icons and then exporting them as jsx components, for example. see this --
github.com/denoland/fresh/blob/mai...

Collapse
 
funnypan profile image
panfan

got it.
do u have try to deploy on vercel?

Thread Thread
 
asheeshh profile image
ashish

i didn't try it, i'd suggest deploying on deno deploy though, runs on edge and has faster deployment

Collapse
 
airtonix profile image
Zenobius Jiricek

iconify. thank me later.

Collapse
 
pyrsmk profile image
Aurélien Delogu

Is the page refreshed at each action? Like is it refreshed when you add a task in the to-do list?

Collapse
 
asheeshh profile image
ashish

no it doesnt

Collapse
 
pyrsmk profile image
Aurélien Delogu • Edited

So there's JavaScript embedded inside the page, isn't it ?

Thread Thread
 
asheeshh profile image
ashish

yes i think, according to what i have read, fresh uses just in time rendering, and also uses partial hydration through islands, and i don't think refreshing on adding a new todo is an expected behavior as i'm not using forms, right?

Thread Thread
 
pyrsmk profile image
Aurélien Delogu

Mmmh ok. I read the documentation a bit. So it seems JS is sent to the client when islands are used, is that it ? Because without it I cannot see how all of this could work ahah.

But that's cool, Fresh seems really equivalent to Phoenix (an Elixir framework). Those hybrid frameworks are the future IMHO.

Thread Thread
 
asheeshh profile image
ashish

yes js is sent to the client when its needed, and not all components are hydrated, only the islands are hydrated i.e. provide interactivity

Collapse
 
bherbruck profile image
bherbruck

Did you get twind autocompletion working in vscode? I couldn't get the plugin working in a deno environment

Collapse
 
asheeshh profile image
ashish

someone in issues helped me out, its working perfectly fine now, see this: github.com/tw-in-js/vscode-twind-i...

Collapse
 
asheeshh profile image
ashish • Edited

Doesn't work for me too, I have opened an issue in the repository regarding this, hopefully they'll fix it soon