MCPcopy
hub / github.com/frejs/fre

github.com/frejs/fre @2.8.9 sqlite

repository ↗ · DeepWiki ↗ · release 2.8.9 ↗
1,301 symbols 3,502 edges 49 files 1 documented · 0%
README

fre logo

Fre

👻 Tiny Concurrent UI library with Fiber.

GitHub License 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.

  • Keyed reconcilation algorithm — Fre has a minimal diff algorithm, It supported keyed, pre-process, offscreen rendering and SSR hydration.

  • Do more with less — Fre get the tiny size, but it has most features, virtual DOM, hooks API, Suspense, Fragments, Fre.memo and so on.

Contributors

Usage

https://deepwiki.com/frejs/fre

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)

Features

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:

t

 }
  })
  const t = useRef(null)
  return 

t


}

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>
}

useContext

import { createContext, useContext } from 'react';

const ThemeContext = createContext(null);

function App() {
  return (
    <ThemeContext value="dark">
      <Button />
    </ThemeContext>
  )
}

function Button({ children }) {
  const theme = useContext(ThemeContext);
  const className = 'button-' + theme;
  return (
    <button class={className}>
      {children}
    </button>
  );
}

Suspense

const Hello = lazy('./hello.js')

export function App() {
  return (



      <Suspense fallback={

loading...

}>
        <Hello />


world!


      </Suspense>



  )
}

ErrorBoundary

function A(){
  throw new Error('render error test')
}

export function App() {
  return (



      <ErrorBoundary fallback={

occur an error

}>
        <A />
      </ErrorBoundary>



  )
}

Fragments

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

jsx

For vite example

export default {
  esbuild: {
    jsxFactory: 'h',
    jsxFragment: 'Fragment',
    jsxInject: `import { h, Fragment } from 'fre'`,
    target: 'es2020',
    format: 'esm'
  }
}

License

MIT @yisar

FOSSA Status

Extension points exported contracts — how you extend this code

RefAttribute (Interface)
(no doc)
jsx-runtime.d.ts
RefObject (Interface)
(no doc)
src/type.ts
IntrinsicAttributes (Interface)
(no doc)
jsx-runtime.d.ts
RefCallback (Interface)
(no doc)
src/type.ts
CSSProperties (Interface)
(no doc)
jsx-runtime.d.ts
IntrinsicAttributes (Interface)
(no doc)
src/type.ts
SVGAttributes (Interface)
(no doc)
jsx-runtime.d.ts
Attributes (Interface)
(no doc)
src/type.ts

Core symbols most depended-on inside this repo

error
called by 197
demo/react/react-dom.js
updateHookTypesDev
called by 70
demo/react/react-dom.js
getComponentName
called by 68
demo/react/react-dom.js
warnInvalidHookAccess
called by 42
demo/react/react-dom.js
I
called by 31
demo/react/react-dom.js
mergeLanes
called by 30
demo/react/react-dom.js
mountHookTypesDev
called by 28
demo/react/react-dom.js
error
called by 28
demo/react/react.js

Shape

Function 1,221
Method 48
Interface 22
Class 8
Enum 2

Languages

TypeScript100%

Modules by API surface

demo/react/react-dom.js868 symbols
docs/docup.fre.min.js166 symbols
demo/react/react.js77 symbols
src/reconcile.ts24 symbols
src/type.ts14 symbols
src/hook.ts14 symbols
demo/src/with-jotal.tsx14 symbols
src/h.ts11 symbols
jsx-runtime.d.ts10 symbols
src/schedule.ts8 symbols
demo/src/benchmark.tsx8 symbols
demo/src/type.tsx7 symbols

Dependencies from manifests, versioned

@skypack/package-check0.2.2 · 1×
codecov3.8.2 · 1×
cross-env5.2.0 · 1×
fre2.5.5 · 1×
nyc15.1.0 · 1×
playwright-test7.2.2 · 1×
preact10.5.13 · 1×
react17.0.2 · 1×
react-dom17.0.2 · 1×
rolldown1.1.0 · 1×
typescript4.0.2 · 1×
vite5.4.21 · 1×

For agents

$ claude mcp add fre \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact