tkh44 / holen

Declarative fetch for React
MIT License
150 stars 16 forks source link

Full support for fetch init options #15

Open jamesplease opened 6 years ago

jamesplease commented 6 years ago

fetch's init option accepts 12 options.

Holen only accepts 5 of the 12. The additional 7 are:

Although these are used less, for full support of the fetch API, Holen should accept these as props.

I believe these propTypes and defaultProps would work:

// propTypes
{
  mode: PropTypes.oneOf([
    'same-origin',
    'cors',
    'no-cors',
    'navigate',
    'websocket'
  ]),
  cache: PropTypes.oneOf([
    'default',
    'no-store',
    'reload',
    'no-cache',
    'force-cache',
    'only-if-cached'
  ]),
  redirect: PropTypes.oneOf(['manual', 'follow', 'error']),
  referrer: PropTypes.string,
  referrerPolicy: PropTypes.oneOf([
    'no-referrer',
    'no-referrer-when-downgrade',
    'origin',
    'origin-when-cross-origin',
    'unsafe-url',
    ''
  ]),
  integrity: PropTypes.string,
  keepalive: PropTypes.bool,
  // This requires checking for the existence of AbortSignal
  signal: PropTypes.instanceOf(AbortSignal)
}
// defaultProps
{
  referrerPolicy: '',
  integrity: '',
  referrer: 'about:client'
}

At the very least, signal should be supported as that is used for aborting fetches 🙂 .

I'd be happy to make a PR for this if you're :+1: Let me know!

tkh44 commented 6 years ago

Sounds great.