react-nil icon indicating copy to clipboard operation
react-nil copied to clipboard

Return data ?

Open tony-go opened this issue 5 years ago • 2 comments

This is more a question than an issue. (sorry for that)

Are those "components" should not return data? Or should react-nil provide a new type of "components" that return data (object, array,...) instead of return null.

Just an idea.

tony-go avatar Sep 17 '20 07:09 tony-go

in react components do not return data but v-dom which goes into the hands of the reconciler. there is no component that receives the return value of another.

you have props

function Foo({ data }) {
  return <Bar data={...} />

render props

<Foo>
  {data => ( ... )}
</Foo>
  • context
  • ref + useImperativeHandle
  • your state manager of choice

i have seen a mini react for node whose components do return data, the problem is that A. this seems kinda shaky because components are async, and B. it would sacrifice the entire react eco system. it could not just go and use redux, react-graphql or whatever on the server.

drcmda avatar Sep 17 '20 07:09 drcmda

Props and render props could work in fact ^^

Thanks for the response ^^

tony-go avatar Sep 17 '20 16:09 tony-go

Implemented this in #12.

CodyJasonBennett avatar Sep 04 '22 04:09 CodyJasonBennett