FredrikOseberg / react-chatbot-kit

MIT License
301 stars 141 forks source link

Attach multiple widgets to a message #38

Open Skyt0a opened 3 years ago

Skyt0a commented 3 years ago

Hi, I try to make a dynamic bot that could be configured by an administrator using your great framework ;)

But I am facing on problem to display multiple widget attach to the same message. I found a solution by creating a special widget that could load the required ones. But I can not access WidgetRegistry to get widget component as the chatbot do. I would like to know if you already have think about this functionality.

Thanks in advance

FredrikOseberg commented 3 years ago

Hi, I try to make a dynamic bot that could be configured by an administrator using your great framework ;)

But I am facing on problem to display multiple widget attach to the same message. I found a solution by creating a special widget that could load the required ones. But I can not access WidgetRegistry to get widget component as the chatbot do. I would like to know if you already have think about this functionality.

Thanks in advance

Hey! Since widgets are just regular React components, I did not think it would be necessary to have the option to render several. If you need to access the same properties as your widget, you can pass them into your components as props:

const MyWidget = (props) => {
     return <div>
           <MyWidget2 {...props} />
           <MyWidget3 {...props} />
     </div>
}

Does that solve your usecase?

alanmrochadeveloper commented 3 years ago

As Fred just said. For me, multiple widgets work, for example, a dynamic Form, which widget is parent form, with children which are no even widgets, since its parent got all props it needs to work and pass to its children.