All Projects → veactjs → veact

veactjs / veact

Licence: MIT license
Mutable state enhancer library for React based on @vuejs

Programming Languages

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

Projects that are alternatives of or similar to veact

mobx-nextjs-root-store
Mobx root store implementation for next.js with server-side rendering
Stars: ✭ 42 (-32.26%)
Mutual labels:  mobx, mobx-react, react-hooks
vesselize
⛵ A JavaScript IoC container that works seamlessly with Vue.js and React.
Stars: ✭ 22 (-64.52%)
Mutual labels:  react-hooks, vue-composition-api, composition-api
BXStage
基于mobx + react 构建一个60多个页面大型跨平台 react-naive 应用
Stars: ✭ 49 (-20.97%)
Mutual labels:  mobx, mobx-react
react-mobx-router4-axios
react + less + webapck config + mobx(store)+ axios + router4
Stars: ✭ 24 (-61.29%)
Mutual labels:  mobx, mobx-react
tinylog-ui
实时日志分析系统后台数据管理系统
Stars: ✭ 45 (-27.42%)
Mutual labels:  mobx, mobx-react
react-native-navigation-mobx-demo
React native Navigation with MobX demo. Blog post write up ->
Stars: ✭ 32 (-48.39%)
Mutual labels:  mobx, mobx-react
team-timesheets
Time tracking web app built as a replacement for old school timesheets.
Stars: ✭ 25 (-59.68%)
Mutual labels:  mobx, mobx-react
use-async-resource
A custom React hook for simple data fetching with React Suspense
Stars: ✭ 92 (+48.39%)
Mutual labels:  react-hooks, react-hook
mobx-react-intl
A connector between mobx-react and react-intl
Stars: ✭ 32 (-48.39%)
Mutual labels:  mobx, mobx-react
react-mobx-local-state-example
React MobX (for Local State) Example
Stars: ✭ 27 (-56.45%)
Mutual labels:  mobx, mobx-react
web
React hooks done right, for browser and SSR.
Stars: ✭ 940 (+1416.13%)
Mutual labels:  react-hooks, react-hook
orkan
A content management toolkit for building and managing dynamic React applications with ease.
Stars: ✭ 25 (-59.68%)
Mutual labels:  mobx, mobx-react
navigation-mobx-example
proof of concept project to use mobX in react-native-navigation
Stars: ✭ 47 (-24.19%)
Mutual labels:  mobx, mobx-react
mobx-wxapp
在小程序中使用mobx
Stars: ✭ 54 (-12.9%)
Mutual labels:  mobx, mobx-react
processor
A simple and lightweight JavaScript data processing tool. Live demo:
Stars: ✭ 27 (-56.45%)
Mutual labels:  react-hooks, vue-composition-api
ecommerce-react-native
The ideal starter kit / app script with all the needed UI elements alongwith MobX and NativeBase to build your iOS and Android e-commerce app like Mona / JackThreads / Canopy / Flipp
Stars: ✭ 86 (+38.71%)
Mutual labels:  mobx, mobx-react
mobx
Код учебного курса “MobX & React” на YouTube-канале webDev (https://tinyurl.com/vt3tk6vy)
Stars: ✭ 23 (-62.9%)
Mutual labels:  mobx, mobx-react
mutable
State containers with dirty checking and more
Stars: ✭ 32 (-48.39%)
Mutual labels:  mobx, mutable
todo-list
A simple todo list application with React and mobx and antd
Stars: ✭ 25 (-59.68%)
Mutual labels:  mobx, mobx-react
Mobx React Lite
Lightweight React bindings for MobX based on React 16.8 and Hooks
Stars: ✭ 2,096 (+3280.65%)
Mutual labels:  mobx, react-hooks

Veact

veact   GitHub stars   npm   Test Codecov   GitHub license

Mutable state enhancer library for React based on @vue/reactivity, with limited interoperability.

Who is using this library 🔥


Installation

npm install veact --save
yarn add veact

Usage

Lifecycle

import React from 'react'
import { onMounted, onBeforeUnmount, onUpdated } from 'veact'

export const Component: React.FC = () => {
  onMounted(() => {
    console.log('component mounted')
  })

  onUpdated(() => {
    console.log('component updated')
  })

  onBeforeUnmount(() => {
    console.log('component will unmount')
  })

  return <div>component</div>
}

Base

import React from 'react'
import { useRef } from 'veact'

export const Component: React.FC = () => {
  const count = useRef(0)
  const increment = () => {
    count.value++
  }

  return (
    <div>
      <span>{count.value}</span>
      <button onClick={increment}>increment</button>
    </div>
  )
}

Reactivity

transform any reactivity object to reactivity hook.

import React from 'react'
import { ref, useReactivity } from 'veact'

// reactivity ref
const countRef = ref(0)

export const Component: React.FC = () => {
  // to reactivity hook
  const count = useReactivity(() => countRef)
  const increment = () => {
    count.value++
  }

  return (
    <div>
      <span>{count.value}</span>
      <button onClick={increment}>increment</button>
    </div>
  )
}

Watch

import React from 'react'
import { useReactive, useWatch } from 'veact'

export const Component: React.FC = () => {
  const data = useReactive({
    count: 0,
  })

  const increment = () => {
    data.count++
  }

  useWatch(data, (newData) => {
    console.log('data changed', newData)
  })

  useWatch(
    () => data.count,
    (newCount) => {
      console.log('count changed', newCount)
    }
  )

  return (
    <div>
      <span>{data.count}</span>
      <button onClick={increment}>increment</button>
    </div>
  )
}

Computed

import React from 'react'
import { useReactive, useComputed } from 'veact'

export const Component: React.FC = () => {
  const data = useReactive({
    count: 4,
    year: 3,
  })

  const total = useComputed(() => {
    return data.count * data.year
  })

  const incrementCount = () => {
    data.count++
  }

  return (
    <div>
      <span>{total.value}</span>
      <button onClick={incrementCount}>incrementCount</button>
    </div>
  )
}

Enhancer

import React from 'react'
import { useReactive, onMounted, batchedUpdates } from 'veact'

export const Component: React.FC = () => {
  const data = useReactive({
    count: 0,
    list: [],
  })

  const fetch = () => {
    fetchData().then((result) => {
      batchedUpdates(() => {
        data.count = result.count
        data.list = result.list
      })
    })
  }

  onMounted(() => {
    fetch()
  })

  return <div>{data.count}</div>
}

API

import {
  // Veact APIs

  // lifecycle
  onMounted,
  onBeforeUnmount,
  onUpdated,

  // data
  useRef,
  useShallowRef,
  useReactive,
  useShallowReactive,
  useComputed,

  // watch
  watch,
  useWatch,
  watchEffect,
  useWatchEffect,

  // enhancer
  useReactivity, // any object data to reactivity data
  batchedUpdates, // batchedUpdates === ReactDOM.unstable_batchedUpdates

  // @vue/reactivity APIs
  ref,
  reactive,
  computed,
  // ...
} from 'veact'

Development

# install dependencies
yarn

# lint
yarn lint

# test
yarn test

# build
yarn build

Changelog

Detailed changes for each release are documented in the release notes.

License

Licensed under the MIT License.

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].