ReferenceError: Cannot access 'variant' before initialization
See original GitHub issueI feel myself a little bit stupid because this should be simple, but I’m not fixing it…
If I try to access to variant in an Complete method, I’ve an error.
const { variant } = useMotion(ref, {
initial: {
y: 0,
scale: maxZoomTimes * 0.8,
opacity: 0
},
enter: {
y: 0,
scale: maxZoomTimes,
opacity: 1,
transition: {
delay: extraDelay,
duration: 800,
onComplete() {
variant.value = 'idle';
}
}
},
idle: {
y: 10,
scale: maxZoomTimes,
opacity: 1,
transition: {
duration: 2000,
repeat: Infinity,
ease: 'easeInOut',
repeatType: 'mirror'
}
}
});
Error: Uncaught (in promise) ReferenceError: Cannot access 'variant' before initialization at Object.onComplete
The code works pefect but I have the error on my console.
I think that this is happening because in the object I’ve external variables like maxZoomTimes
and JavaScript evaluates the object before variant exist, if instead of using variables you have a raw object everything works fine.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ReferenceError: Cannot access 'steps' before initialization
The error is telling you that the variable steps is initialized on line 7, but you're using it on line 6 to set...
Read more >ReferenceError: Cannot access before initialization in JS
The "Cannot access before initialization" error occurs when a variable declared using let or const is accessed before it was initialized in the...
Read more >HMR error: Cannot access '...' before initialization · Issue #3033
Describe the bug The error happens when I try to edit component, that Wrap in connect function (redux) Is inside dependency loop There...
Read more >cannot access before initialization webpack - You.com | The AI ...
This might be caused by a cyclic dependencies (i.e. moduleA imports module B and vice versa at the same time). Take a deeper...
Read more >ReferenceError: can't access lexical declaration 'X' before ...
The JavaScript exception "can't access lexical declaration `variable' before initialization" occurs when a lexical variable was accessed ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Meanwhile we wait for an official answer I have a kind of workaround… not my best code but I’ll work.
First of all I’ve created some custom types:
and then…
Is not with typescript support, is it?