Skip to content

Partial update 를 허용할지 논의 #9

@JeGwan

Description

@JeGwan

private getNextState(currentState: T, newState: T | Updater<T>): T {
if (typeof newState === 'function') {
return (newState as Updater<T>)(currentState)
}
const isNonNullObject = (value: unknown): value is object =>
typeof value === 'object' && value !== null
if (isNonNullObject(currentState) && isNonNullObject(newState)) {
return { ...currentState, ...newState } as T
}
return newState as T
}

현재는 객체의 경우 무조건 리렌더링이 일어날 수 밖에 없는데요 (line 66)
아마도 부분 업데이트를 위해서 만들어둔 것 같은데,
불변성에 익숙한 리액트 사용자들에게 굳이 이렇게 제공할 필요 있는지 논의해보고싶습니다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions