Skip to content
Discussion options

You must be logged in to vote

Hi @cqh963852,

Regarding your demo, you can make the values of the items list nested states of string. In this way, the oninput event handler needs only to update the value state, instead of refreshing the entire items list.

Thus, your program can be modified like this:

const VanTodoList = () => {
  const items = van.state<Record<number, State<string>>>({});
  let count = 0;

  return van.tags.div(
    van.tags.button(
      {
        onclick: () => {
          items.val = { ...items.oldVal, [count++]: van.state("") };
        },
      },
      "add item"
    ),
    () => {
      return van.tags.div(
        Object.entries(items.val).flatMap(([key, value]) => {
          return van.tags.i…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Tao-VanJS
Comment options

Answer selected by Tao-VanJS
Comment options

You must be logged in to vote
1 reply
@efpage
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants