skip to Main Content

i’m expecting this to be something very simple that I am too tired and overlooked, but hoping someone can help!

I have a function that my parent component inherits from the provider. I am attempting to pass the function to the child with the below:

console.log(typeof(runServerless))
<VaultEntry contactInfo={userData} runServerless={runServerless}/>

That console log shows a array and if I directly log the function, it shows the function. Now, immediately upon VaultEntry:

export const VaultEntry = (contactInfo, runServerless) => {
      console.log(runServerless)
}

that console.log returns a blank object and I can’t call it.

Soooo hoping someone knows what thing I am missing. Appreciate all the help! Thank yoU!

2

Answers


  1. function components take props as first argument

    export const VaultEntry = (props) => {
          console.log(props.runServerless)
    }
    

    If you want the props values directly without props.runServerless you need to deconstruct the props argument on declaration inline

    export const VaultEntry = ({ contactInfo, runServerless }) => {
          console.log(props.runServerless)
    }
    
    Login or Signup to reply.
  2. You just have to descructure it like:

    export const VaultEntry = ({contactInfo, runServerless}) => {
          console.log(runServerless)
    }
    

    so add {} in props and it should work fine

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search