Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-react",
"version": "3.9.0",
"version": "4.0.0",
"description": "React hooks for data fetching",
"main": "dist/index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/components/FetchConfigAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { FetchConfigSync } from './server'
export async function FetchConfigAsync(props: FetchContextType) {
const { children, defaults = {}, value = {} } = props

let $values = new Map()
const $values = new Map()

const previousConfig = $context.value as any
const previousConfig = $context.value as typeof $context.value

for (let valueKey in value) {
for (const valueKey in value) {
const $value = await value[valueKey]

const $data = $value.data ?? $value
Expand All @@ -22,7 +22,7 @@ export async function FetchConfigAsync(props: FetchContextType) {
// cacheProvider.set(resolvedKey, $data)
}

for (let defaultKey in defaults) {
for (const defaultKey in defaults) {
const { id = defaultKey } = defaults[defaultKey]

if (isDefined(id)) {
Expand All @@ -32,7 +32,7 @@ export async function FetchConfigAsync(props: FetchContextType) {
}
}

let mergedConfig = {
const mergedConfig = {
...previousConfig,
...props,
headers: {
Expand Down
6 changes: 3 additions & 3 deletions src/components/LocalStorageCacheProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ let isCacheHydrated = false

const loadFromLocalStorage = () => {
if (typeof localStorage !== 'undefined') {
for (let key in localStorage) {
for (const key in localStorage) {
try {
const currentValue = localStorage.getItem(key)
if (typeof currentValue !== 'undefined') {
defaultCache.set(key, JSON.parse(currentValue!))
}
} catch (error) {
} catch {
// Remove cache key if parsing fails
localStorage.removeItem(key)
}
Expand Down Expand Up @@ -51,7 +51,7 @@ export function LocalStorageCacheProvider({
useCacheHydration({ instant })

return (
// @ts-expect-error
//@ts-expect-error
<FetchConfig
cacheProvider={{
get(k) {
Expand Down
12 changes: 7 additions & 5 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function FetchConfig(props: FetchContextType) {

const $values = new Map()

for (let valueKey in value) {
for (const valueKey in value) {
const resolvedKey = serialize({
idString: serialize(valueKey)
})
Expand All @@ -66,7 +66,9 @@ export function FetchConfig(props: FetchContextType) {

if (dataChunk instanceof Promise) {
try {
const parsedChunkValue = JSON.parse((dataChunk as any).value)
const parsedChunkValue = JSON.parse(
(dataChunk as unknown as { value: string }).value
)
parsedChunk = parsedChunkValue?.data ?? parsedChunkValue
} catch {
parsedChunk = dataChunk
Expand All @@ -86,7 +88,7 @@ export function FetchConfig(props: FetchContextType) {
}
}

for (let defaultKey in defaults) {
for (const defaultKey in defaults) {
const { id = defaultKey } = defaults[defaultKey]
const resolvedKey = serialize({
idString: serialize(id)
Expand All @@ -102,14 +104,14 @@ export function FetchConfig(props: FetchContextType) {
}
}

for (let suspenseKey of suspense) {
for (const suspenseKey of suspense) {
const key = serialize({
idString: serialize(suspenseKey)
})
willSuspend.set(key, true)
}

let mergedConfig: FetchContextType = {
const mergedConfig: FetchContextType = {
...previousConfig,
...props,
headers: {
Expand Down
Loading
Loading