Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
next-ssr-form
Advanced tools
> **⚠️⚠️ This is an experimental library and is likely to be discontinued ⚠️⚠️**
next-ssr-form
⚠️⚠️ This is an experimental library and is likely to be discontinued ⚠️⚠️
getServerSideProps
to receive post data and provide helpers to the page to render the formmutation
s' return values are inferred.(Peer) Dependencies:
Table of contents:
ℹ️ Easiest thing to do is to look at the pages in
examples/typescript
.
yarn add next-ssr-form@next zod formik
In a Next.js page/..
:
export const createPostForm = createForm({
schema: z.object({
from: z.string().min(2),
message: z.string().min(4),
}),
defaultValues: {
message: "",
from: "",
},
formId: "createPost",
});
getServerSideProps
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
const createPostProps = await createPostForm.getPageProps({
ctx,
/**
* Your mutation function
* - Will only be called when there's a POST to this form based on the `formId`
* - 🌟 The `input` will be validated by the schema & the types inferred!
*/
async mutation(input) {
return DB.createPost(input);
},
});
return {
props: {
// spread properties onto the prop
...createPostProps,
posts: await DB.getAllPosts(),
},
};
};
type Props = InferGetServerSidePropsType<typeof getServerSideProps>;
export default function Home(props: Props) {
// ...
Your data usage is now typesafe!
pages/formik-scaffold.tsx
orpages/index.tsx
pages/vanilla.tsx
type Props = InferGetServerSidePropsType<typeof getServerSideProps>;
export default function Home(props: Props) {
const [feedback, setFeedback] = useState(
createPostForm.getFeedbackFromProps(props)
);
const initalValues = createPostForm.getInitialValues(props);
const initialErrors = createPostForm.getInitialErrors(props);
return (
<>
<h1>Normal http post (zod for validation)</h1>
<p>
Uses a standard <code><form></code> with the <code>action</code>
-attribute to post to the same page. Form data is handled in{' '}
<code>getServerSideProps</code> and feedback is passed through page
props.
</p>
<h2>My guestbook</h2>
{props.posts.map(item => (
<article key={item.id}>
<strong>
From {item.from} at {item.createdAt}:
</strong>
<p className="message">{item.message}</p>
</article>
))}
<h3>Add post</h3>
<form action={props.createPost.endpoints.action} method="post">
<p className={`field ${initialErrors?.from ? 'field--error' : ''}`}>
<label>
Your name:
<br />
<input type="text" name="from" defaultValue={initalValues.from} />
{initialErrors?.from && (
<span className="field__error">{initialErrors.from}</span>
)}
</label>
</p>
<p className={`field ${initialErrors?.message ? 'field--error' : ''}`}>
<label>
Your message:
<br />
<textarea name="message" defaultValue={initalValues.message} />
{initialErrors?.message && (
<span className="field__error">{initialErrors.message}</span>
)}
</label>
</p>
<input type="submit" />
<br />
{feedback?.state === 'success' && (
<span className="feedback success">Yay! Your entry was added</span>
)}
{feedback?.state === 'error' && (
<>
<span className="feedback error">
Something went wrong: {feedback.error.message}. Full Error:{' '}
<pre>
{JSON.stringify(
{
...feedback.error,
message: feedback.error.message,
stack: feedback.error.stack,
},
null,
4
)}
</pre>
</span>
</>
)}
</form>
</>
);
}
FAQs
> **⚠️⚠️ This is an experimental library and is likely to be discontinued ⚠️⚠️**
The npm package next-ssr-form receives a total of 19 weekly downloads. As such, next-ssr-form popularity was classified as not popular.
We found that next-ssr-form 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.