This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cancelling callbacks on useReturn unmount
- Loading branch information
1 parent
4440fd3
commit 68d7430
Showing
3 changed files
with
101 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState } from "react"; | ||
import { useEasybase } from 'easybase-react'; | ||
import CardElement from "./DbCardElement"; | ||
|
||
const ChildUseReturn = () => { | ||
const [ratingState, setRatingState] = useState(50); | ||
|
||
const { | ||
db, | ||
useReturn, | ||
e | ||
} = useEasybase(); | ||
|
||
const { frame, loading } = useReturn(() => db() | ||
.return() | ||
.where(e.lt('rating', ratingState)) | ||
.limit(10), | ||
[ratingState]); | ||
|
||
return ( | ||
<div> | ||
<div style={{ display: "flex", alignItems: "center" }}> | ||
{loading ? <div className="loader"></div> : frame.map((ele, index) => <CardElement {...ele} index={index} key={index} />)} | ||
</div> | ||
<div className="button-row"> | ||
<div className="d-flex align-items-center"> | ||
<p className="m-4">Edit Rating filter: </p> | ||
<input type="number" onChange={e => setRatingState(+e.target.value)} value={ratingState} /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const UseReturnStressTest = () => { | ||
const [showChild, setShowChild] = useState(true); | ||
|
||
const { | ||
db, | ||
} = useEasybase(); | ||
|
||
const onAddPage = async () => { | ||
await db().insert({ rating: 68, "app name": "Inserted App", _position: 0 }).all(); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<button className="btn green" onClick={onAddPage}><span>Add<br />Card</span></button> | ||
<label> | ||
Show Child: | ||
<input type="checkbox" onChange={e => setShowChild(e.target.checked)} checked={showChild} /> | ||
</label> | ||
|
||
{ showChild && <ChildUseReturn /> } | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default UseReturnStressTest; |
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