create-packer 1.17.6 → 1.17.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.17.6",
3
+ "version": "1.17.7",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -0,0 +1 @@
1
+ export { default as useComponentInstance } from './useComponentInstance'
@@ -0,0 +1,21 @@
1
+ import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes, useEffect, useRef } from 'react'
2
+ import { componentInstance } from '@/providers'
3
+
4
+ export default function useComponentInstance<
5
+ P extends Record<string, any>,
6
+ Refs extends Record<string, any>
7
+ >(
8
+ key: string,
9
+ Component: ForwardRefExoticComponent<PropsWithoutRef<any> & RefAttributes<Refs>>,
10
+ props?: P
11
+ ) {
12
+ const $instance = useRef<(Refs & componentInstance.refsType<P>) | null>(null)
13
+
14
+ useEffect(() => {
15
+ componentInstance.create(key, Component, props).then(instance => {
16
+ $instance.current = instance
17
+ })
18
+ }, [])
19
+
20
+ return $instance
21
+ }
@@ -3,7 +3,6 @@ import {
3
3
  ForwardRefExoticComponent,
4
4
  PropsWithoutRef,
5
5
  RefAttributes,
6
- useEffect,
7
6
  useImperativeHandle,
8
7
  useRef,
9
8
  useState
@@ -12,7 +11,7 @@ import { createRoot } from 'react-dom/client'
12
11
 
13
12
  const instanceMap: Record<string, any> = {}
14
13
 
15
- interface refsType<P> {
14
+ export interface refsType<P> {
16
15
  $setProps: (newProps?: P) => void
17
16
  $updateProps: (newProps?: Partial<P>) => void
18
17
  }
@@ -60,19 +59,3 @@ export async function create<P extends Record<string, any>, Refs extends Record<
60
59
  $instance.$setProps(props)
61
60
  return $instance
62
61
  }
63
-
64
- export function useHooks<P extends Record<string, any>, Refs extends Record<string, any>>(
65
- key: string,
66
- Component: ForwardRefExoticComponent<PropsWithoutRef<any> & RefAttributes<Refs>>,
67
- props?: P
68
- ) {
69
- const $instance = useRef<Refs & refsType<P>>(instanceMap[key])
70
-
71
- useEffect(() => {
72
- create(key, Component, props).then(instance => {
73
- $instance.current = instance
74
- })
75
- }, [])
76
-
77
- return $instance
78
- }