microlinkhq / open

4 stars 2 forks source link

React Hooks for MQL #32

Open oyeanuj opened 4 years ago

oyeanuj commented 4 years ago

Hi @Kikobeats, I'm excited to use the library again!

I'm using it in React and I'm curious if you plan to introduce a Hook for consuming MQL. I'm building custom previews, so would love to be able to leverage MQL in a way that feels more natural. Maybe like:

const { urlInfo, setUrl } = useMQL(url)
const { domain, favicon, /* ... */  } = urlInfo
...

const { screenshotInfo, setUrl } = useScreenshot(url)

Thoughts?

Kikobeats commented 4 years ago

Hello, @oyeanuj

That could be a super nice thing to use under React ecosystem!

mql is the official Microlink HTTP client. For getting a screenshot, the code looks like:

const { data, response } = await mql(url, {
  screenshot: true,
  meta: false
})

const screenshotUrl = data.screenshot.url

Build a hook op top of that code should be a trivial thing. I didn't it before cause it was enough for me.

Since you said you are going to use mql a lot these days, can you please do some proof of concept of what could be a good API for the hook? 🙂

Just keep in mind there is a lot of query parameters that can be passed against mql for getting a more precise response.

Also, take a look to swr, feel both can be work together in a very well way 🙂