Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: Cannot read properties of undefined when i put default prop

I try to create a custom hook

const useX({name}) = () =>{ 
return name??"no name";
}

Then i use:

const customHook = useX();

Exist any way to create a functional component with optional props without typescript?
I try it, but get same error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const useX({name:"DEFAULT"}) 
const useX({name:""})
const useX({name:{})

>Solution :

Might be there are a few syntax errors in your code. try this code:-

const useX = ({ name = "DEFAULT" } = {}) => {
  return name ?? "no name";
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading