0

I have a child component of a component. And I want to get and use its placeholder attribute. How can I do this?

I tried the following

<Namer>
    <input placeholder="firstname" type="text"/>
</Namer>

component code

function Namer({children}){
    return <div>
        {children.map(child=>{
            <>
                <label>{child.getAttribute("placeholder")}</label>
                {child}
            </>
        })}
    </div>
}

1 Answer 1

1

Found it in the propsfield of the component. so I used child.props.placeholder

children.map(child=>{
    <>
        <label>{child.props.placeholder}</label>
        {child}
    </>
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.