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

resolveData on root #482

Closed
joaojoyce opened this issue May 13, 2024 · 3 comments
Closed

resolveData on root #482

joaojoyce opened this issue May 13, 2024 · 3 comments

Comments

@joaojoyce
Copy link

joaojoyce commented May 13, 2024

Hi. Is resolveData() on root object currently working? I'm having a hard time triggering it.

I can't do it on Puck load, nor using resolveAllData()

Here's a simple root object...It renders the title as null, even after calling resolveAllData(). I can't see the console.log also, so I believe it is not being triggered.

{
    fields: {
        title: {
            type: "text",
        }
    },
    resolveData: async ({ props }) => {    
        console.log("RESOLVING DATA")
        return {
          props: {
            title: "Test"
          },
        };
    },
    render: ({title,children}) => {
        return (
            <div className="contentroot">
                <div>
                    <h1>{title}</h1>
                </div>
                <div>
                    {children}
                </div>
                <div>
                    <h1>Footer</h1>
                </div>
            </div>
        )
    }
}

Am I doing something wrong?

@chrisvxd
Copy link
Member

Hi @joaojoyce! Thanks for your report, but unfortunately I'm unable to reproduce. I tried copying your code snippet above into the demo application and the resolver ran fine.

If you can share a repo or codepen which reproduces the issue, I can investigate further.

@joaojoyce
Copy link
Author

joaojoyce commented May 18, 2024

Hi @chrisvxd ,

I found out that resolveData doesn't work if I pass properties to <Puck />. I also get the warning that passing properties to <Puck /> is deprecated.

So this does work:

<Puck config={config} />

This doesn't

<Puck 
          overrides={{headerActions:()=>(...)}}
          onChange={(data) => {onChange({ target: {  name, value: JSON.stringify(data)}})}} 
          data={initialData} config={config}  >
</Puck>

Is this intended? It's very convenient and intuitive to pass these properties to puck directly. Also, this makes it easy to abstract generic configs that would work the same on <Puck /> and on <Render />.

For instance, the onChange and overrides that I have here aren't needed on my frontend where I render...

@joaojoyce
Copy link
Author

Nevermind. It was my initialData that was not built correctly.

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

No branches or pull requests

2 participants