Js.React. How do i search dom elements?

Example

    const handleRightClick = (e) => {
        const house = document.getElementById('1'); // << vanila js :))
        if (house) house.setAttribute('margin-left', '200px');
        house.style.marginLeft = '100px';
    }

FullCode

import {useState} from 'react';
import React from "react";
import styles from './NavigationBar.module.css';

export const NavigationBar = () => {

    const leftButtonValue = '<';
    const rightButtonValue = '>';

    const [myName, setMyName] = useState(0);

    const handleRightClick = (e) => {
        const house = document.getElementById('1');
        if (house) house.setAttribute('margin-left', '200px');
        house.style.marginLeft = '100px';
    }

    return (
        <div className={styles.navigation}>
            <progress className={styles.progress} value="0" max="100"></progress>

            <button className={styles.buttons__left} >
                {leftButtonValue}
            </button>
            <button className={styles.buttons__right} onClick={handleRightClick} >
                {rightButtonValue}
            </button>
        </div>
    );
}
This entry was posted in Без рубрики. Bookmark the permalink.