Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

fre-server

NotificationsYou must be signed in to change notification settings

frejs/fre-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

server rendering for fre, It is still in the experimental stage, do not use it for production environment.

Use

const{ h}=require('fre')const{ renderToString, useAction}=require('fre/server')functionApp(){const[posts,setPosts]=useState([])useAction(async()=>{awaitaxios.get('https://api.clicli.us/rank').then(res=>{setPosts(res.data.posts)})})return(<div>{posts.map(item=>(<li>{item.title}</li>))}</div>)}router.get('/',asyncctx=>{letcontent=awaitrenderToString(<App/>)ctx.body=template.replace('<!-- fre -->',content)})

RenderToString

letcontent=awaitrenderToString(<App/>)ctx.body=template.replace('<!-- fre -->',content)

renderToString will return html strings, you can render with Koa or any other frameworks.

UseAction

useAction(async()=>{awaitaxios.get('https://api.clicli.us/rank').then(res=>{// do somethins})})

useAction is more likeuseEffect, but it has no cleanups, and it receives a promise function. the requests will excutes in server side.

MIT ©hkc452 inspired bypreact

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp