Skip to content

Commit

Permalink
refactor: access methods directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 10, 2019
1 parent b43785b commit 8a41cee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
23 changes: 13 additions & 10 deletions packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,19 @@ function Microlink (props) {
[isLazyEnabled, hasIntersected]
)

const fetchData = useCallback(() => {
if (canFetchData) {
setLoading(true)
const fetch = isFunction(setData)
? Promise.resolve({})
: fetchFromApi(props.url, apiUrl, apiUrlProps)

fetch.then(({ data }) => mergeData(data))
}
}, [apiUrl, canFetchData, setData, apiUrlProps])
const fetchData = useCallback(
() => {
if (canFetchData) {
setLoading(true)
const fetch = isFunction(setData)
? Promise.resolve({})
: fetchFromApi(props.url, apiUrl, apiUrlProps)

fetch.then(({ data }) => mergeData(data))
}
},
[apiUrl, canFetchData, setData, apiUrlProps.headers['x-api-key']]
)

const mergeData = useCallback(
fetchData => {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css } from 'styled-components'
import mql from '@microlink/mql'
import { fetchFromApi, getApiUrl as createApiUrl } from '@microlink/mql'

const REGEX_HTTPS = /^https/
const REGEX_LOCALHOST = /http:\/\/localhost/
Expand Down Expand Up @@ -38,7 +38,7 @@ export const getApiUrl = ({
media,
...opts
}) =>
mql.getApiUrl(url, {
createApiUrl(url, {
apiKey,
video: media.includes('video'),
screenshot: media.includes('screenshot'),
Expand All @@ -47,7 +47,7 @@ export const getApiUrl = ({
...opts
})

export const fetchFromApi = mql.fetchFromApi
export { fetchFromApi }

export const isLarge = cardSize => cardSize === 'large'

Expand Down

0 comments on commit 8a41cee

Please sign in to comment.