Comments (5)
What react does is, if you don't pass inputs
it takes the first argument of the hook as input:
// useCallback
const inputsNext = inputs !== undefined && inputs !== null ? inputs : [callback];
const dirty = shallowEqualsArray(inputsNext, inputsPrev);
from melody.
Hey Malte 😃I've created a codesandbox to see React's behavior (open the console):
https://codesandbox.io/s/52ylkpl26p
From what I can see:
useEffect(fn => cleanup(), inputs)
will runfn
on mount. Also, thecleanup
function andfn
will run on every update ifinputs
is an array of values that have changed (or isundefined
).useMemo(fn, inputs)
will re-runfn
every time theinputs
changes (or isundefined
).useCallback(fn, inputs)
is equal touseMemo(() => fn, inputs)
.
If any of the above are passed a constant array (eg. []
or ['constValue']
) as inputs
, then fn
will only run once.
If on a re-render any of the above have inputs === undefined
and fn
is changed, the new fn
will be run, so useEffect(fn)
is actually useEffect(fn, [fn])
.
I've not seen Melody's behaviour, but I presume it is different right now?
from melody.
I think it makes sense to align the behaviour. That'd make it more predictable.
from melody.
Hey @jamesb3ll 😍
yes, that's the behaviour that makes sense and that we also should implement. I will create a PR soon
from melody.
Has been fixed in #80
from melody.
Related Issues (20)
- Q: How is it possible to render a template on server side and hydrate on client side? HOT 6
- melody-streams parent-child rendering broken
- Child components aren't mounted if the document root is another HTML tag than used in the root component
- Improvements in github actions
- Drop access to props.value to avoid bugs
- Twig ~ operator does not compile correctly
- Set default options for dispatchCustomEvent HOT 3
- Removes prefetch for async components
- Q: How to write a custom filter
- Fix peer dependency mismatch in melody packages
- Improve warnings for `melody-streams`
- Input element value goes out of sync from component state field it's bound to
- packages/melody-parser: Unclosed and several closing element tag cause `ERROR: Unknown tag` HOT 3
- Possible missing Operator "=>" in the filter filter HOT 2
- Homepage design errors
- Allow tags in attributes HOT 2
- CVE-2023-45133 - melody-extension-core > babel-template > babel-traverse HOT 1
- TypeScript: Update tooling or remove
- Reduce amount of packages
- Setup Release Automation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from melody.