framesjs/frames.js

Allow React.Fragment as children of Frame

Closed this issue · 4 comments

I know this example is not the cleanest code, but this code is throwing an error

      {(() => {
        if (state.screen === "home") {
          return <FrameButton onClick={dispatch}>PLAY</FrameButton>;
        }
        if (state.screen === "overview") {
          return (
            <>
              <FrameButton onClick={dispatch}>PRESS</FrameButton>
              <FrameButton onClick={dispatch}>REFRESH</FrameButton>
            </>
          );
        }
        if (state.screen === "button") {
          return <FrameButton onClick={dispatch}>HOME</FrameButton>;
        }

        return null;
      })()}
 ⨯ node_modules/frames.js/dist/next/server.js (542:14) @ eval
 ⨯ Error: invalid child of <Frame>, must be a <FrameButton> or <FrameImage>
    at stringify (<anonymous>)

I know I could probably rearchitecture my app to not need it, but I would think it's a use case that should be supported, no?

yeah it could be - just a question of priority. you could also return an array instead of the fragment and it'd work

Ah yeah that could also work!

I'm happy to wip up a PR that just uses https://github.com/grrowl/react-keyed-flatten-children instead of the built-in React.Children if you want.

sounds like a good way to do it

we've changed the API in frames.js v0.9 whereby react fragments are no longer relevant. Thanks for the feedback, closing this