0.1.2 • Published 7 years ago
subscribe-form v0.1.2
subscribe-form
Debounced subscribe form build with React. Under development.
Usage
Simply run yarn add subscribe-form
or npm install subscribe-form
if you prefer, and then use it in your components like that.
import React from 'react'
import { Form } from 'subscribe-form'
export default class MyComponent extends React.Component {
handleSubmit(email, fullName) {
const encodedEmail = `email=${encodeURIComponent(email)}`
const encodedFullName = `fullName=${encodeURIComponent(fullName)}`
const url = `http://endpoint.com/?${encodedEmail}&${encodedFullName}`
window.fetch(url).then(response => response.json())
.then(data => console.log(data))
}
render() {
return (
<div>
<h1>Subscribe</h1>
<Form handleSubmit={handleSubmit} />
</div>
)
}
}
You can pass your own handleSubmit
function that will be called only when the form is valid. It will have as arguments email
and fullName
.
Test
You can see a working example in the storybook, just run yarn storybook
.
License
MIT © Andrea Amorosi