DEV Community

Discussion on: New React Hooks Pattern? Return a Component

Collapse
 
phelpa profile image
Plínio Helpa

I just used your article to create a hook that returns a textEditor (the JSX) and the functions that my component needs.

My line of thought was : If the JSX is tied to the the functions, it makes more sense to use a hook that gives everything instead of importing the JSX separately.

Collapse
 
droopytersen profile image
Andrew Petersen • Edited

Yeah that's where I landed too. If the hook is coupled to the UI any way, why not? One thing I've been noodling on lately is flipping it. Where component has the hook tacked on it.

import Modal from "./Modal"
// then use the hook like 
let modal = Modal.useModal({ ...stuff } )

// and use the component like 
<Modal {...modal.modalProps }>
  ....
</Modal>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
droopytersen profile image
Andrew Petersen

I took the idea described above and tried to capture it in in a new blog post, Compound Components with a Hook