Skip to content

Commit

Permalink
fix(renderComponent): 生成默认 key 值
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Dec 30, 2020
1 parent e1916d8 commit ceae5f1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/react/renderComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { isPromiseLike } from '../utils'
import { PickBy } from 'vtils/types'
import { useUpdate } from 'react-use'

Expand Down Expand Up @@ -53,13 +54,19 @@ export function renderComponent<TComponent extends React.ComponentType<any>>(
let destroy!: () => void

const prepareProps = (props: Partial<React.ComponentProps<TComponent>>) => {
props = { ...props }
props = {
key: Date.now(),
...props,
}
if (injectCallbacks) {
for (const key of Object.keys(injectCallbacks)) {
const originalCallback = props[key]
;(props as any)[key] = async () => {
await originalCallback?.()
await (injectCallbacks as any)[key]()
;(props as any)[key] = () => {
const res = originalCallback?.()
if (isPromiseLike(res)) {
return res.then(() => (injectCallbacks as any)[key]())
}
return (injectCallbacks as any)[key]()
}
}
}
Expand Down

0 comments on commit ceae5f1

Please sign in to comment.