All Projects β†’ yisar β†’ Fre

yisar / Fre

Licence: mit
πŸ‘» Tiny Footprint Concurrent UI library for Fiber.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fre

useAudioPlayer
Custom React hook & context for controlling browser audio
Stars: ✭ 176 (-94.49%)
Mutual labels:  hooks, hook, react-hooks
react-ui-hooks
🧩Simple repository of React hooks for building UI components
Stars: ✭ 20 (-99.37%)
Mutual labels:  hooks, hook, react-hooks
Preact Render Spy
Render preact components with access to the produced virtual dom for testing.
Stars: ✭ 178 (-94.43%)
Mutual labels:  vdom, jsx
Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (-96.34%)
Mutual labels:  hooks, hook
React Intersection Observer
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
Stars: ✭ 2,689 (-15.84%)
Mutual labels:  hooks, hook
Reason Reactify
πŸš€ Transform a mutable tree into a functional React-like API
Stars: ✭ 102 (-96.81%)
Mutual labels:  hooks, jsx
Graphql Hooks
🎣 Minimal hooks-first GraphQL client
Stars: ✭ 1,610 (-49.61%)
Mutual labels:  hooks, react-hooks
Useworker
βš›οΈ useWorker() - A React Hook for Blocking-Free Background Tasks
Stars: ✭ 2,233 (-30.11%)
Mutual labels:  hooks, hook
Ysf
YSF Server Functions
Stars: ✭ 77 (-97.59%)
Mutual labels:  hooks, hook
15 Puzzle
The 15-puzzle is a sliding puzzle that consists of a frame of numbered square tiles in random order with one tile missing, built in react
Stars: ✭ 161 (-94.96%)
Mutual labels:  hooks, jsx
Omi
Front End Cross-Frameworks Framework - ε‰η«―θ·¨ζ‘†ζžΆθ·¨εΉ³ε°ζ‘†ζžΆ
Stars: ✭ 12,153 (+280.38%)
Mutual labels:  vdom, jsx
Pinst
🍺 dev only postinstall hooks (package.json)
Stars: ✭ 162 (-94.93%)
Mutual labels:  hooks, hook
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (-97.09%)
Mutual labels:  hooks, hook
React Selector Hooks
Collection of hook-based memoized selector factories for declarations outside of render.
Stars: ✭ 84 (-97.37%)
Mutual labels:  hooks, hook
Hooks
A high-quality & reliable React Hooks library.
Stars: ✭ 7,841 (+145.41%)
Mutual labels:  hooks, react-hooks
Karet
Karet is a library that allows you to embed Kefir observables into React VDOM
Stars: ✭ 81 (-97.46%)
Mutual labels:  vdom, jsx
React Universal Hooks
πŸŽ‰ React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!
Stars: ✭ 148 (-95.37%)
Mutual labels:  hooks, hook
React Nprogress
βŒ›οΈ A React primitive for building slim progress bars.
Stars: ✭ 173 (-94.59%)
Mutual labels:  hooks, hook
Wonders
🌈 Declarative JavaScript framework to build command-line applications.
Stars: ✭ 34 (-98.94%)
Mutual labels:  vdom, jsx
Fontmod
Simple hook tool to change Win32 program font.
Stars: ✭ 1,064 (-66.7%)
Mutual labels:  hooks, hook

fre logo

Fre

πŸ‘» Tiny Concurrent UI library with Fiber.

Build Status Code Coverage npm-v npm-d brotli

  • Concurrent Mode β€” This is an amazing idea, which implements the coroutine scheduler in JavaScript, it also called Time slicing.

  • O(ND) reconcilation algorithm β€” Fre has a minimal longest-increasing-subsequence algorithm, It supported keyed, pre-process.

  • Do more with less β€” After tree shaking, project of hello world is only 1KB, but it has most features, virtual DOM, hooks API, Fragments and so on.

Sponsors

Contributors

Use

yarn add fre
import { render, useState } from 'fre'

function App() {
  const [count, setCount] = useState(0)
  return <>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>+</button>
    </>
}

render(<App/>, document.body)

Hooks API

useState

useState is a base API, It will receive initial state and return an Array

You can use it many times, new state is available when component is rerender

function App() {
  const [up, setUp] = useState(0)
  const [down, setDown] = useState(0)
  return (
    <>
      <h1>{up}</h1>
      <button onClick={() => setUp(up + 1)}>+</button>
      <h1>{down}</h1>
      <button onClick={() => setDown(down - 1)}>-</button>
    </>
  )
}

useReducer

useReducer and useState are almost the same,but useReducer needs a global reducer

function reducer(state, action) {
  switch (action.type) {
    case 'up':
      return { count: state.count + 1 }
    case 'down':
      return { count: state.count - 1 }
  }
}

function App() {
  const [state, dispatch] = useReducer(reducer, { count: 1 })
  return (
    <>
      {state.count}
      <button onClick={() => dispatch({ type: 'up' })}>+</button>
      <button onClick={() => dispatch({ type: 'down' })}>-</button>
    </>
  )
}

useEffect

It is the execution and cleanup of effects, which is represented by the second parameter

useEffect(f)       //  effect (and clean-up) every time
useEffect(f, [])   //  effect (and clean-up) only once in a component's life
useEffect(f, [x])  //  effect (and clean-up) when property x changes in a component's life
function App({ flag }) {
  const [count, setCount] = useState(0)
  useEffect(() => {
    document.title = 'count is ' + count
  }, [flag])
  return (
    <>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>+</button>
    </>
  )
}

If it returns a function, the function can do cleanups:

useEffect(() => {
  document.title = 'count is ' + count
  return () => {
    store.unsubscribe()
  }
}, [])

useLayout

More like useEffect, but useLayout is sync and blocking UI.

useLayout(() => {
  document.title = 'count is ' + count
}, [flag])

useMemo

useMemo has the same rules as useEffect, but useMemo will return a cached value.

const memo = (c) => (props) => useMemo(() => c, [Object.values(props)])

useCallback

useCallback is based useMemo, it will return a cached function.

const cb = useCallback(() => {
  console.log('cb was cached.')
}, [])

useRef

useRef will return a function or an object.

function App() {
  useEffect(() => {
    console.log(t) // { current:<div>t</div> }
  })
  const t = useRef(null)
  return <div ref={t}>t</div>
}

If it uses a function, it can return a cleanup and executes when removed.

function App() {
  const t = useRef((dom) => {
    if (dom) {
      doSomething()
    } else {
      cleanUp()
    }
  })
  return flag && <span ref={t}>I will removed</span>
}

Fragments

// fragment
function App() {
  return <>{something}</>
}
// render array
function App() {
  return [a, b, c]
}

jsx2

plugins: [
  [
    '@babel/plugin-transform-react-jsx',
    {
      runtime: 'automatic',
      importSource: 'fre',
    },
  ],
]

Compare with other frameworks

The comparison is difficult because the roadmap and trade-offs of each framework are different, but we have to do so.

  • react

React is the source of inspiration for fre. Their implementation and asynchronous rendering are similar. The most amazing thing is concurrent mode, which means that react and fre have the same roadmap -- Exploring concurrent use cases.

But at the same time, fre has obvious advantages in reconciliation algorithm and bundle size.

  • vue / preact

To some extent, vue and preact are similar. They have similar synchronous rendering, only the API is different.

The reconciliation algorithm of fre is similar to vue3, but the biggest difference is that vue/preact do not support concurrent mode, this means that the roadmap is totally different.

framework concurrent offscreen reconcilation algorithm bundle size
fre2 √ √ β˜…β˜…β˜…β˜… 2kb
react18 √ √ β˜…β˜… 43kb
vue3 Γ— x β˜…β˜…β˜…β˜…β˜… 33kb
preactX Γ— x β˜…β˜…β˜… 4kb

License

MIT @yisar

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].