Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
Why $ is a String and not Identifier in React Js

This line of codes get error

listRef.current.style.transform = 'translateX(${230 + distance}px)'

    import { ArrowBackIosOutlined, ArrowForwardIosOutlined } from '@material-ui/icons';
    import React, { useRef } from 'react'
    import "./list.scss";
    import ListItem from "../listItem/ListItem";
    
    export default function List() {
    
      const listRef = useRef()
    
      const handleClick = (direction) => {
        let distance = listRef.current.getBoundingClientRect().x - 50
        if(direction === "left"){
          listRef.current.style.transform = 'translateX(${230 + distance}px)'
        }
      }
    
      return (
        <div className='list'>
            <span className="listTitle">Continue to watch</span>
            <div className="wrapper">
                <ArrowBackIosOutlined className="sliderArrow left" onClick={()=>handleClick("left")}/>
                <div className="container" ref={listRef}>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                    <ListItem/>
                </div>
                <ArrowForwardIosOutlined className="sliderArrow right" onClick={()=>handleClick("right")}/>
            </div>
        </div>
      )
    }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change you code from

 const handleClick = (direction) => {
    let distance = listRef.current.getBoundingClientRect().x - 50
    if(direction === "left"){
      listRef.current.style.transform = 'translateX(${230 + distance}px)'
    }
  }

to

 const handleClick = (direction) => {
    let distance = listRef.current.getBoundingClientRect().x - 50
    if(direction === "left"){
      listRef.current.style.transform = `translateX(${230 + distance}px)`
    }
  }

What you need is called template literal in js.

Type Template Literal:

Mac: Shift + ` on keyboard

Refer to: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!