Home > Software design >  How to delete the content of an input bar after sending this content?
How to delete the content of an input bar after sending this content?

Time:08-20

I created a chat application in solid-js. However when a user sends a message from the chat input bar, the message is not automatically cleared from the bar after sending. So that the content from the input bar to be cleared automatically after sending a message, I wrote the following code:

 <input
              type="text"
              name="content"
              id="content"
              value={content()}
              onInput={(e) => setContent(e.currentTarget.value)}
            />

            . . .

            <Show when={content().trim().length}>
              <button
                onClick={() =>{
                 content().trim().length==null
                }
                }
              >
                <BiSolidSend />
              </button>
            </Show>

But that didn't work, so I changed my code to:

<button
  onClick={() =>{
                delete content()
                }
                }
>

But it still didn't work. Thanks !

CodePudding user response:

Use setContent to make it an empty string:

<button onClick={()=>{setContent("")}}>
    Button
</button>
  • Related