-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ropali/fix/infinite-list-card-render
fix: Container List component re-renders infinitely
- Loading branch information
Showing
3 changed files
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import React, { createContext, useState, useContext, useCallback } from 'react'; | ||
import { invoke } from '@tauri-apps/api/tauri'; | ||
import React, {createContext, useCallback, useContext, useState} from 'react'; | ||
import {invoke} from '@tauri-apps/api/tauri'; | ||
|
||
const ContainerContext = createContext(); | ||
|
||
export function ContainerProvider({ children }) { | ||
const [containers, setContainers] = useState([]); | ||
const [selectedContainer, setSelectedContainer] = useState(null) | ||
export function ContainerProvider({children}) { | ||
const [containers, setContainers] = useState([]); | ||
const [selectedContainer, setSelectedContainer] = useState(null) | ||
|
||
const loadContainers = useCallback(() => { | ||
invoke('fetch_containers').then((newContainers) => { | ||
setContainers(newContainers); | ||
}); | ||
}, []); | ||
const loadContainers = useCallback(() => { | ||
invoke('fetch_containers').then((newContainers) => { | ||
setContainers(newContainers); | ||
}); | ||
}, []); | ||
|
||
|
||
|
||
|
||
return ( | ||
<ContainerContext.Provider value={{ containers, selectedContainer, loadContainers, setSelectedContainer }}> | ||
{children} | ||
</ContainerContext.Provider> | ||
); | ||
return ( | ||
<ContainerContext.Provider value={{containers, selectedContainer, loadContainers, setSelectedContainer}}> | ||
{children} | ||
</ContainerContext.Provider> | ||
); | ||
} | ||
|
||
export function useContainers() { | ||
return useContext(ContainerContext); | ||
return useContext(ContainerContext); | ||
} |