Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): Fix setSession function type to receive partial session #1172

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

igorbrasileiro
Copy link
Contributor

@igorbrasileiro igorbrasileiro commented Mar 15, 2022

What's the purpose of this pull request?

Fix ContextValue setSession function type.

How it works?

setSession function allows receiving partial session as parameter input, but the type says that need to pass session.
before:

export interface ContextValue extends Session {
  setSession: (session: Session) => void
}
// ...
const value = useMemo(
    () => ({
      ...session,
      setSession: (data: Session) => setSession({ ...session, ...data }),
    }),
    [session, setSession]
  )

after:

export interface ContextValue extends Session {
  setSession: (session: Partial<Session>) => void
}
// ...
const value = useMemo<ContextValue>(
    () => ({
      ...session,
      setSession: (data) => setSession({ ...session, ...data }),
    }),
    [session, setSession]
  )

After the fix, is possible to pass partial session:

const { setSession } = useSession()
setSession({ postalCode: 'foo' })

How to test it?

base.store Deploy Preview

vtex-sites/base.store#388

References

@igorbrasileiro igorbrasileiro requested a review from a team as a code owner March 15, 2022 16:59
@igorbrasileiro igorbrasileiro self-assigned this Mar 15, 2022
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4543b93:

Sandbox Source
Store UI Typescript Configuration

@filipewl filipewl requested a review from a team March 15, 2022 17:54
@igorbrasileiro igorbrasileiro merged commit c1c3cea into master Mar 16, 2022
@igorbrasileiro igorbrasileiro deleted the chore/fix-session-sdk branch March 16, 2022 16:24
Copy link
Member

@eduardoformiga eduardoformiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants