Skip to content

Why create a new signal in a Field for Monetary amounts? #270

Open
@qingzhoufeihu

Description

@qingzhoufeihu

What are the differences between the two versions of the code below?

<Field
  name="price"
  type="number"
  transform={toCustom((value) => value && value * 100, {
    on: 'change',
  })}
>
  {(field, props) => {
    const value = useSignal<string | number>('');
    useSignalEffect(() => {
      if (!Number.isNaN(field.value.value)) {
        input.value =
          field.value.value === undefined ? '' : field.value.value / 100;
      }
    });
    return <input {...props} type="number" value={value.value} />;
  }}
</Field>
<Field
  name="price"
  type="number"
  transform={toCustom((value) => value && value * 100, {
    on: 'change',
  })}
>
  {(field, props) => {
    return <input {...props} type="number" value={field.value.value === undefined ? '' : field.value.value / 100} />;
  }}
</Field>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions