Help with some JSX logic in Typescript on an Advanced Resizing Component
I am working on making a custom resizing component wrapper for my app. I have the resizing logic all working as i would like it to, however i am trying to implement
edge handlers
so that i can attach the resize event handlers to the edge of a child component.
Here is the github gist to my resizer.tsx
The following is an example usage:
However this approach is not working, i will post the error below.17 Replies
error:
This error isn't really making sense to me, tbh. Iam passing everything as
JSXElement
.
Is there A: a solution to the error itself or B: an alternative approach that is more idiomatic.I think the way to do this is to use the
children
helper
interesting, haven't seen this yet. Will look at the docs.
Where does
body
come from?its just a variable
yeah, i see that now. Just read too fast.
š
i get:
how does body go from
JSX.Element
to never
?uhh, that shouldn't happen
You should define children the same as you have in
Resizer
props
JSXElement | ((edgeHandler: JSXElement) => JSXElement)
then in Resizer just
Hha, yup, you're right. Interestingly enough, i am one step closer.
however, it seems that i am not doing something correctly:
in
ResizerContent
you need to pull edgehandler
prop out in the splitProps usage
const [, rest] = splitProps(props, ['class', 'edgeHandler'])
indeed, but when i do that, my handler is not attached. I don't see it in the DOM, nor are my event handlers being added.
huh ...
hmm
Could you show what you have now?
Yup, one minute. Ill update the gist.
gist is updated, and that's the example file that i am working with to test it.
I was able to find the
ResizeContent
component in the DOM:though i can't see any event handlers attached to it.
you aren't using the edgeHandler anywhere though
š¤¦š» i forgot to use it in the div
okay, my event handles are attached, though it is binding to the parent, not the child.
so close, thanks for the help.
the entire reason i am going through this is to try and attach the resize handler top the child of the
Resizer
. That way the resize is triggered by clicking on the edge of the child, not the Resizer
.You want it attached to the
aside
or the edgeHandler
?
also a possible better way to do this is provide callbacks to the children in the render function
or a contextwell, the
aside
is just an example - but yes, i want it to attach to the first child element passed to the Resizer
. Essentially the Resizer
is a wrapper that allows me to resize the child when i drag on it. I originally wanted to "clamp" the Resizer
to always be the same size as the child that is being resized, but then i thought attaching the events handler itself to the child would be better.
Providing a callback was my original plan, but i think i over-complicated it tbh.
A context wouldn't be too nice, as i want this component to be generic and able to wrap any component that i decide should be resizable.
Thank you very much, i solved the problem.
I was over complicating it, like usual.
Just put the Resizer
in the div i want to resize. That solved it. Duh.
Tht way i am automatically bound. Haha, better than a wrapper tbh.