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

Best way of handling temporal state of user component while editing #153

Open
spadgeaki opened this issue Dec 15, 2020 · 1 comment
Open

Comments

@spadgeaki
Copy link

I want to have checkbox in related.settings (SignUpFormSettings) that switches SignUpForm layout to "Thank you message". I was thinking of using node.data.custom.showSubmitted value but custom state is getting persisted.

SignUpForm.craft = {
    displayName: "SignUpForm",
    props: {
        className:
            "w-full bg-gray-200 rounded-lg p-2 flex flex-col m-2 md:mx-auto md:mt-0 md:w-1/2 xl:w-1/4",
    },
    custom: {
        showSubmitted: false,
    },
    related: {
        settings: SignUpFormSettings,
    },
}

Is there a recommended way of temporary switching UI state like this without it persisting in exported state?

@matdru
Copy link
Collaborator

matdru commented Jan 8, 2021

Craft doesn't have a concept of permanent vs temporary state, this is more of an implementation detail on your side, and it's up to you to decide which parts of the state you want to save or the whole thing as is. If you want to use craft state to store temporary data, make sure to strip it away outside of craft before you save it somewhere.

Alternatively you can use other state manager to hold this information, for example adding SignUpFormContext around settings and editor that can hold this information for you, so you can toggle it from SignUpFormSettings and read the value in SignUpForm.

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

No branches or pull requests

2 participants