@midwayjs/next-hooks-compiler
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@midwayjs/next-hooks-compiler

Midway Hooks compiler

Demo

Compile built-in hooks

source

import { useContext } from '@midwayjs/hooks'

export function useQuery(id: string) {
  const { query } = useContext()
  return query[id] || ''
}

output

export function useQuery(id: string) {
  const _req_ctx = this
  const { query } = _req_ctx.ctx.hooks.useContext()
  return query[id] || ''
}

Compile reference

source

import { useContext } from '@ali/midway-hooks'

export function useQuery(id: string) {
  const { query } = useContext()
  return query[id] || ''
}

export function useResponse() {
  const name = useQuery('hello')
  return name
}

output

export function useQuery(id: string) {
  const _req_ctx = this
  const { query } = _req_ctx.ctx.hooks.useContext()
  return query[id] || ''
}

export function useResponse() {
  const _req_ctx = this
  const name = useQuery.bind(_req_ctx)('hello')
  return name
}

Readme

Keywords

none

Package Sidebar

Install

npm i @midwayjs/next-hooks-compiler

Weekly Downloads

14

Version

1.0.3

License

MIT

Unpacked Size

107 kB

Total Files

46

Last publish

Collaborators

  • mariodu
  • czy88840616
  • legendecas
  • echosoar
  • lellansin
  • lxxyx
  • stone-jin