Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
Editable div content

I make a table containing some rules, i added a button so the user can edit any row onclicking on the edit button. i want to change the clicked row only not all rows. also i want to blur on the required row when the user click edit button.

const[isEditing, setIsEditing] = useState(false)
const onEditHandler = (event:any) =>{
        const editedRuleId = (event.target.id);
        
        setIsEditing(!isEditing);
    }

  <div className='container'>  
                {Object.entries(rules).map((rule) => (
                    <div key={rule[0]} className='tbl_rules'>
                        <div className='box-1'><h6>{rule[0]}</h6></div>
                        <div contentEditable={isEditing} className='box-2'>{rule[1]}</div>
                        <div className='box-3'>
                            <button 
                                id={rule[0]}
                                type="button" 
                                className="btn btn-sm btn-info"
                                onClick={onEditHandler}
                            >{isEditing ? 'Save' : 'Edit'}</button>
                        </div>
                    </div>
                ))}    
            </div> 
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Best way to do this would be to make each row a unique component. So you would end up with code that looks like this:

<div className='container'>  
  {Object.entries(rules).map((rule) => (
     <Rule rule={rule}>
   ))}    
</div> 

And in the Rule component, you would add the rest of your code as follows which will allow each row to hold its own state:

const[isEditing, setIsEditing] = useState(false)
const onEditHandler = (event:any) => {
  const editedRuleId = (event.target.id);
  
  setIsEditing(!isEditing);
}

return (<div key={rule[0]} className='tbl_rules'>
  <div className='box-1'><h6>{rule[0]}</h6></div>
  <div contentEditable={isEditing} className='box-2'>{rule[1]}</div>
    <div className='box-3'>
      <button 
        id={rule[0]}
        type="button" 
        className="btn btn-sm btn-info"
        onClick={onEditHandler}
        >
      {isEditing ? 'Save' : 'Edit'}</button>
   </div>
  </div>);
about 4 years ago · Juan Pablo Isaza Denunciar

0

const [ selectedCell, setSelectedCell ] = useState(null) ;

<div className='container'>  
    {
        Object.entries(rules).map( ([rule, id]) => 
            return {
                <div key={id} className='tbl_rules'>
                    {
                        rule.map((item, index) => {
                            <div className='box-1'
                                contentEditable={selectedCell === id+"_"+index}
                                onClick={() => setSelectedCell(id+"_"+index)}
                            >
                                {item}
                            </div>
                        })
                    }
                </div>
            }
        )
    }    
</div> 

# for example rules
{
    row_1 : ["rule_1_1", "rule_1_2"],
    row_2 : ["rule_2_1", "rule_2_2"]
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda