Giter VIP home page Giter VIP logo

Comments (16)

KarolError404 avatar KarolError404 commented on June 17, 2024 1

Did you try to use useConfirm(...) in child component? I can see it happening when you're wrapping component in and use useConfirm(...) in the same component.

from material-ui-confirm.

atompie avatar atompie commented on June 17, 2024 1

Ok I got it . I Wrapped Autocomplete in ConfirmProvider but it is too deep. Thanks. A great work with material-ui-confirm :)

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

Did you wrap the whole app component tree in ConfirmProvider?

from material-ui-confirm.

gardengeek99 avatar gardengeek99 commented on June 17, 2024

Yes, I am using MuiThemeProvider and originally had ConfirmProvider as a child. However, I removed MuiThemeProvider ensuring ConfirmProvider was outermost and still the same issue.

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

And I assume you are calling useConfirm in a functional component in that component tree? Seems weird, are there any significant differences between your usage and the demo?

from material-ui-confirm.

gardengeek99 avatar gardengeek99 commented on June 17, 2024

I am. I don't see anything very different from the samples.

from material-ui-confirm.

gardengeek99 avatar gardengeek99 commented on June 17, 2024

I guess one somewhat significant difference is my app is typescript.

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

I see, I don't have any other ideas for why it wouldn't work without some kind of reproduction : <

from material-ui-confirm.

magnusvk avatar magnusvk commented on June 17, 2024

@KarolError404 thanks for that pointer—this is what I was doing to run into this. Perhaps this could be more clear in the docs?

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

That's generally the case for the context provider + hooks pattern, common in many packages. I added a tiny clarification to the readme (043ccd4).

@gardengeek99 does this match your case?

from material-ui-confirm.

magnusvk avatar magnusvk commented on June 17, 2024

Yes that’s helpful for someone like me who is still new to React, thank you!

from material-ui-confirm.

atompie avatar atompie commented on June 17, 2024

Hi I ave the same issue: undefined confirm.

import { useConfirm, ConfirmProvider } from 'material-ui-confirm';

export default function TagTextForm({label, placeholder, onChange}) {
    const classes = useStyles();
    const confirm = useConfirm();
    console.log(confirm)   //undefined
    const handleChange = (ev, value, reason) => {
        console.log("confirm", confirm) //undefined
    }

    return (
        <div className={classes.root}>
            <ConfirmProvider>
                <Autocomplete
                    multiple
                    id="tags-text"
                    onChange={(ev, value, reason) =>
                    ....
                />
            </ConfirmProvider>
        </div>
    );
}

What I am doing wrong?

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

@atompie the TagTextForm component needs to itself be wrapped in ConfirmProvider. Generally you want to keep ConfirmProvider at the very top level in the App component, similarly to router, theme provider, etc.

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

Since there is no reproduction, I'm going to close this for now.

from material-ui-confirm.

sneko avatar sneko commented on June 17, 2024

I had this issue too:

  • In my Next.js project it worked great
  • In my Storybook wrapping my stories with the general decorator was not working with ConfirmProvider whereas all my other providers work great

My "workaround" is to set the wrapper component in another file then to use it inside preview.jsx. I can't explain why... hope this helps!

from material-ui-confirm.

jonatanklosko avatar jonatanklosko commented on June 17, 2024

Interesting, it does work for the stories in this repo:

storiesOf("Confirmation dialog", module)
.addDecorator((getStory) => <ConfirmProvider>{getStory()}</ConfirmProvider>)
.add("basic", () => <Basic />)

from material-ui-confirm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.