Teact: Fix for useState

This commit is contained in:
Alexander Zinchuk 2021-05-09 03:11:42 +03:00
parent 691440b5b2
commit 75d72fe884

View File

@ -447,10 +447,6 @@ export function useState<T>(initial?: T): [T, StateHookSetter<T>] {
value: initial, value: initial,
nextValue: initial, nextValue: initial,
setter: ((componentInstance) => (newValue: ((current: T) => T) | T) => { setter: ((componentInstance) => (newValue: ((current: T) => T) | T) => {
if (!componentInstance.isMounted) {
return;
}
if (byCursor[cursor].nextValue !== newValue) { if (byCursor[cursor].nextValue !== newValue) {
byCursor[cursor].nextValue = typeof newValue === 'function' byCursor[cursor].nextValue = typeof newValue === 'function'
? (newValue as (current: T) => T)(byCursor[cursor].value) ? (newValue as (current: T) => T)(byCursor[cursor].value)
@ -466,8 +462,8 @@ export function useState<T>(initial?: T): [T, StateHookSetter<T>] {
console.log( console.log(
'[Teact.useState]', '[Teact.useState]',
componentInstance.name, componentInstance.name,
// eslint-disable-next-line max-len // `componentInstance.Component` may be set to `null` by GC helper
(componentInstance.Component as FC_withDebug).DEBUG_contentComponentName componentInstance.Component && (componentInstance.Component as FC_withDebug).DEBUG_contentComponentName
? `> ${(componentInstance.Component as FC_withDebug).DEBUG_contentComponentName}` ? `> ${(componentInstance.Component as FC_withDebug).DEBUG_contentComponentName}`
: '', : '',
`Forced update at cursor #${cursor}, next value: `, `Forced update at cursor #${cursor}, next value: `,