
Security News
Opengrep Adds Apex Support and New Rule Controls in Latest Updates
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
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 hydrate.
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.
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)
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
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>
</>
)
}
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()
}
}, [])
More like useEffect, but useLayout is sync and blocking UI.
useLayout(() => {
document.title = 'count is ' + count
}, [flag])
useMemo
has the same rules as useEffect
, but useMemo
will return a cached value.
const memo = (c) => (props) => useMemo(() => c, [Object.values(props)])
useCallback
is based useMemo
, it will return a cached function.
const cb = useCallback(() => {
console.log('cb was cached.')
}, [])
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>
}
import { createContext, useContext } from 'react';
const ThemeContext = createContext(null);
function App() {
return (
<ThemeContext.Provider value="dark">
<Button />
</ThemeContext.Provider>
)
}
function Button({ children }) {
const theme = useContext(ThemeContext);
const className = 'button-' + theme;
return (
<button class={className}>
{children}
</button>
);
}
const Hello = lazy('./hello.js')
export function App() {
return (
<div>
<Suspense fallback={<div>loading...</div>}>
<Hello />
<div>world!</div>
</Suspense>
</div>
)
}
// fragment
function App() {
return <>{something}</>
}
// render array
function App() {
return [a, b, c]
}
plugins: [
[
'@babel/plugin-transform-react-jsx',
{
runtime: 'automatic',
importSource: 'fre',
},
],
]
MIT @yisar
FAQs
Tiny Concurrent UI library with Fiber.
The npm package fre receives a total of 190 weekly downloads. As such, fre popularity was classified as not popular.
We found that fre demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.