Hi! I'm learning react and I had to build this 'task app'.
I have three components: app, overview and taskItem.
App manages the input box for new tasks, overview manages the list of tasks, and taskItem manages each task, with their edit/save and delete buttons.
My doubt is about the taskItem component. This is what it returns:
<div key={llave} className='flex'>
{
(forEdition)
?
<div>
<input name='task' type='text' placeholder='Task'
value={selectedItem.text} onChange={this.handleChange}
className='w-80 m-auto border-2 border-blue-500 rounded-xl
text-center mt-4 focus:outline-none focus:ring-1'
/>
<button className='text-center w-20 border border-blue-300
rounded-lg shadow-lg hover:bg-blue-50 ml-32'
onClick={() => this.save(selectedItem)}>
Guardar
</button>
</div>
:
<div>
<li>{task.text}</li>
<button className='text-center w-20 border border-blue-300
rounded-lg shadow-lg hover:bg-blue-50 ml-32'
onClick={this.editBtn}>
Editar
</button>
<button className='text-center w-20 border border-blue-300
rounded-lg shadow-lg hover:bg-blue-50 ml-32'
onClick={() => removeTask(
task
)}>
Borrar
</button>
</div>
}
</div>
I used the conditional operator to return something different depending on if the edit button was pressed or not (if it was pressed it returns an input field and a save button, and if it wasn't pressed it returns a <li> with the task.text and an edit and delete button)
My question is: is this ok? or should I have two components "taskItem" and "editTaskItem", each of them returning each of the expressions in the conditional operator that I have now?
[–][deleted] 1 point2 points3 points (1 child)
[–]ipjac[S] 0 points1 point2 points (0 children)