DEV Community

loading...

React Hook, to copy?

yobretyo profile image Bret ・1 min read

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

Discussion

pic
Editor guide
Collapse
ivanjeremic 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 Author

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 Author

So by className?