
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A flexible React form library
npm i formk --save
or yarn
yarn add formk
import formk from "formk";
import { useState } from "react";
const { Form, Field } = formk();
const LoginForm = () => {
const [formValue, setFormValue] = useState({
username: "admin",
password: "admin",
});
return (
<Form value={formValue} onChange={setFormValue}>
<Field name="username" />
<Field name="password" />
<button type="submit">Submit</button>
</Form>
);
};
const LoginForm = () => {
return (
<Form value={formValue} onChange={handleChange}>
<Field
name="username"
rules={{
// indicate that username field is required
required: true,
// use custom error message
message: "Username required",
}}
/>
<Field
name="password"
rules={{
// no error message specified
// default error message will be used
required: true,
}}
/>
<button type="submit">Submit</button>
</Form>
);
};
import React, { useState } from "react";
import { Text, View, StyleSheet, Button, TextInput } from "react-native";
import formk from "formk";
const { Form, Field } = formk({
noExtraAttrs: true,
});
const initialValue = {
username: "admin",
password: "123456",
};
export default function App() {
const [currentData, setCurrentData] = useState(initialValue);
const [submittedData, setSubmittedData] = useState(initialValue);
return (
<View style={styles.container}>
<View>
<Form
value={currentData}
initialValue={initialValue}
onChange={setCurrentData}
onSuccess={setSubmittedData}
>
{({ handleSubmit }) => (
<>
<Field name="username" rules={{ required: true }}>
{({ $props, val }) => (
<View>
<TextInput
{...$props("value", "onChangeText")}
style={styles.input}
placeholder="Username"
/>
{val.error && (
<Text style={styles.error}>{val.error.message}</Text>
)}
</View>
)}
</Field>
<Field
name="password"
label="Custom Field Name"
rules={{ required: true }}
>
{({ $props, val }) => (
<View>
<TextInput
{...$props("value", "onChangeText")}
style={styles.input}
placeholder="Password"
/>
{val.error && (
<Text style={styles.error}>{val.error.message}</Text>
)}
</View>
)}
</Field>
<Button title="Submit" onPress={handleSubmit} />
</>
)}
</Form>
</View>
<View>
<Text>
Current Data:{"\n"}
{JSON.stringify(currentData, null, 2)}
{"\n"}
Submitted Data:{"\n"}
{JSON.stringify(submittedData, null, 2)}
{"\n"}
</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 50,
backgroundColor: "#ecf0f1",
padding: 8,
},
input: {
borderColor: "silver",
borderWidth: 1,
marginBottom: 5,
padding: 5,
borderRadius: 3,
},
error: {
color: "red",
marginBottom: 5,
},
});
import formk from "formk";
import faker from "faker";
import { useState } from "react";
const { Form, Field } = formk();
const initialValue = {
loginInfo: {
username: faker.internet.userName(),
password: faker.internet.password(),
},
personalInfo: {
email: faker.internet.email(),
address: {
zipCode: parseInt(faker.address.zipCode(), 10),
city: faker.address.city(),
street: faker.address.streetAddress(),
country: faker.address.country(),
},
},
};
const LoginInfo = () => (
<>
<Field name="username" label="Username" rules={{ required: true }} />
<Field
name="password"
label="Password"
rules={{ required: true, min: 6 }}
/>
</>
);
const AddressInfo = () => (
<>
<Field name="zipCode" label="ZipCode" rules={{ pattern: /^\d+$/ }} />
<Field name="city" label="City" />
<Field name="street" label="Street" />
<Field name="country" label="Country" />
</>
);
const PersonalInfo = () => (
<>
<Field
name="email"
label="Email"
rules={{ type: "email", required: true }}
/>
<Form name="address">
<AddressInfo />
</Form>
</>
);
export default function App() {
const [value, setValue] = useState(initialValue);
const [submittedValue, setSubmittedValue] = useState(initialValue);
return (
<div className="App">
<Form
value={value}
initialValue={initialValue}
onChange={setValue}
onSuccess={setSubmittedValue}
>
<Form name="loginInfo">
<LoginInfo />
</Form>
<Form name="personalInfo">
<PersonalInfo />
</Form>
<button>Save</button>
</Form>
<h2>Editing value</h2>
<xmp>{JSON.stringify(value, null, 2)}</xmp>
<h2>Submitted value</h2>
<xmp>{JSON.stringify(submittedValue, null, 2)}</xmp>
</div>
);
}
FAQs
A powerful form library for ReactJs/ReactNative
We found that formk 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.