Search code examples
javascriptreactjsreduxreact-reduxarrayobject

remove the textfield on button click not working reactjs


I have multiple date textfield with close button, on clicking on close(x) should delete the textfield, But not working,( remove the textfield on clicking on close button ) Here is my codelink https://codesandbox.io/s/strange-http-zhj4f


Solution

  • Better to code your map() this way

    {closedatearr.map(datevalue => {
              return (
                <div className="text-content" key={datevalue.toString()}>
                  <input type="text" value={datevalue} className="inputfield" readOnly />
                  <button
                    type="button"
                    onClick={() => this.textareaHandler(datevalue)}
                  >
                    X
                  </button>
                </div>
              );
            })}