DEV Community

Bret
Bret

Posted on

React Hook, to copy?

im trying to make a react hook to copy a "snippet" of code that ill have created, but, how do I make that happen?

function About() {
const [copy, setcopy] = useState(document.getElementsByClassName(
document.getElementById("test")
))

return (
    <div>
        <h1 className="test">ABOUT PAGE</h1>
        <input id="input" type="text"/>
        <button id="copy">Copy</button>
    </div>
)
Enter fullscreen mode Exit fullscreen mode

}

export default About

Top comments (3)

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

So first of all in react we don't use id to interact with the elements, if you want to copy the user input of the input element you must do it the react way.

Collapse
 
yobretyo profile image
Bret

What would the react way be?

import React, { useState } from 'react'

function Snippets() {
return (

    </div>
)

}

function Snippet() {
const [copy, useCopy] = useState(true)
const [snippet, setSnippet] = useState([
{
name: 'post 1',
text: 'sample post',
},
]);
}

export default Snippets

Collapse
 
yobretyo profile image
Bret

So by className?