-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: this.state.draggedStyle is null #109
Comments
Hey. 😁 Can you let me now which version you're using? Since this has only started happening since you moved to typescript then I imagine the issue could be caused by something in your build/typescript config (however there are a number of things that could have caused it). Side note: I plan to re-write this lib in typescript, just haven't found the need/time yet. 😊 |
Thanks for the response!
Yes; the error is seen when the cursor moves after a drag has been started. It only occurs after the hold time has passed and the component is actually mobile.
Sure, here's the relevant code (can't give access to the repo):
My tsconfig.json:
src/components/WidgetWrapper/WidgetWrapper.tsx:
WidgetWrapper.module.sass:
I'm new to Typescript, so you're probably right about the issue being something I'm doing wrong. It's unlike any other typed language I've used. (Almost) everything should be up to date, as I (recently) created the app using the latest version of create-react-app with the typescript template and node.js, only adding latest (or latest stable) versions of packages.
Totally understand. Even just adding type declarations for now would help, ie.:
|
UPDATE 3
Unfortunately, I was unable to find the root cause. If you see an issue with my code, please let me know. I will try to find the time to make a minimal, reproducible example. The fact that
draggedStyle
is set correctly every second mouse event leads me to believe that this is a bug inreact-reorder
. The only workaround I found involved forkingreact-reorder
, I opted to usereact-dnd
instead, which is a lot more complicated, but it works.UPDATE 2
I couldn't tell you the root problem. I'm also having a different issue causing me to be unable to debug the application (connection refused), so I'm relying on
console.log
. Logging every timedraggedStyle
is written to with something vs. null, I would not expect it to be null when this error occurs, but it is. Every second time. However, this seems to fix the issue:This seems to have no side-effects, and reordering, drag and drop are perfectly smooth.
My only issue now is one that I also had before this: If I drag an item from "left-side" to "right-side" or vice versa, the component disappears from the source list and its "ghost" (my translucent clone placeholder) appears in the destination list (as expected) while still dragging. When I release it, it goes back to its source list, in the same position. Note that both lists have the same components.
UPDATE 1
Second time writing this update for some reason. Props are set correctly, and the stylesheet is also loaded. The names match up, and the bug has nothing to do with
draggedClassName
. I noticed something weird when inspectingstate
where the error occurs: It's only sometimes undefined. I narrowed it down to not being set on children inrender
:In the above code,
draggedStyle
will beundefined
ifchild.props.style
isundefined
andisDragged
isfalse
. The child would be myWidgetWrapper
, which in the default state has no style. I thought the fix would be:But this still isn't working. The expectation that
style.transform
is defined also needs to be dealt with. Still investigating.ORIGINAL BODY
Edit: Irrelevant info removed
I'm using
react-reorder
with Typescript and self-declared types (please add types!). Before migrating to Typescript, it was working fine. Now, when I drag a component, I get this output in the console:I'm using a
Reorder
component withdraggedClassName={widgetStyles.Dragged}
, wherewidgetStyles
is a sass stylesheet imported aswidgetStyles
.widgetStyles.Dragged
resolves to something likeWidgetWrapper_Dragged__3VyWh
, but even using a regular css stylesheet with just.dragged { styles go here }
and using "dragged" asdraggedClassName
results in the same error.The console prints the error on every mouse event (edit: turns out to be every second mouse event) and it's very laggy. Traceback excerpt:
The text was updated successfully, but these errors were encountered: