/sharyn-browser

Helpers functions for the browser

Primary LanguageJavaScriptMIT LicenseMIT

🌹 @sharyn/browser

clearCaches

clearCaches(reload=false, hardReload=true): Clears all the caches used by service workers.

const UpdateBanner = () => (
  <div>
    A new version of the app is available!
    <a onClick={() => clearCaches(true)}>Click here to update</a>
  </div>
)

getFormData

getFormData(formElement, omitEmptyFields=false): Gives you the FormData of a form element.

const Form = () => {
  const form = useRef(null)
  return (
    <>
      <form ref={form}>
        <input name="firstname" />
        <input name="lastname" />
      </form>
      <button onClick={() => console.log(getFormData(form.current))}>
        Log all form values
      </button>
      <button onClick={() => console.log(getFormData(form.current, true))}>
        Log truthy form values
      </button>
    </>
  )
}

This package is part of @sharynjs/sharyn.