
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@baethon/polaris-form-hook
Advanced tools
React hook for form state management in @shopify/polaris. It eliminates the necessity for individual useState
and useCallback
for each form field and simplifies form data management.
Based on the original example from Polaris docs.
import {Form, FormLayout, Checkbox, TextField, Button} from '@shopify/polaris';
import {useCallback} from 'react';
import {useForm} from '@baethon/polaris-form-hook';
function FormOnSubmitExample() {
const form = useForm({
newsletter: false,
email: '',
);
const handleSubmit = useCallback(() => {
form.reset();
}, []);
return (
<Form onSubmit={handleSubmit}>
<FormLayout>
<Checkbox
label="Sign up for the Polaris newsletter"
{...form.register.checked('newsletter')}
/>
<TextField
{...form.register.value('email')}
label="Email"
type="email"
autoComplete="email"
helpText={
<span>
We’ll use this email address to inform you on future changes to
Polaris.
</span>
}
/>
<Button submit>Submit</Button>
</FormLayout>
</Form>
);
}
npm i @baethon/polaris-form-hook
Import useForm
from @baethon/polaris-form-hook
:
import {useForm} from '@baethon/polaris-form-hook';
The function takes one argument - object with initial form data:
const form = useForm({
first_name: '',
last_name: '',
});
You have to pass all fields that will be used in the form.
The form
object (created by useForm()
) contains a register
property.
It's an object containing factory methods that should be used to bind a field with Polaris component.
Polaris is inconsistent in names of the value properties. Depending on the component, it will use value
, selected
, or checked
properties to pass the values. The register
object will have a method for each of them.
The factory method will generate two properties: value
(or selected
, checked
) and onChange()
.
const form = useForm({
first_name: '',
accept_terms: false,
company_name: [],
});
(
<TextField label="First name" {...form.register.value('first_name')} />
<Checkbox label="Accept Terms" {...form.register.checked('accept_terms')} />
<ChoiceList
title="Company name"
choices={[
{label: 'Hidden', value: 'hidden'},
{label: 'Optional', value: 'optional'},
{label: 'Required', value: 'required'},
]}
{...form.register.selected('company_name')
/>
)
To access the form data, use form.data
.
const form = useForm({
first_name: '',
accept_terms: false,
company_name: [],
});
console.log(form.data.first_name);
You can update a single field using:
form.setField('first_name', 'Jon');
Or by passing an object that will be merged with the form data:
form.update({ last_name: 'Snow' });
To reset the form use:
form.reset();
reset()
will use the initial form data.
npm test
FAQs
Simple form hook for @shopify/polaris
The npm package @baethon/polaris-form-hook receives a total of 10 weekly downloads. As such, @baethon/polaris-form-hook popularity was classified as not popular.
We found that @baethon/polaris-form-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.