0

I am developing a react component to display errors, success, and other messages.

The component takes the props type and message. Type determines the styling of the message, and message is the content itself. I need to build this component to be scalable, and creating conditional rendering isn't feasible as the number of variables and functions needed would grow exponentially as the number of messages increased. I need a way to render only when required with changing props (such as a specific unknown error message).

For example, something like:

onClick={() => <Message type={req.body.errorType} message="Internal Server Error" />}

Is this even possible?

To my knowledge, I am not asking the same thing as other "Condition rendering" questions, as the answers to this, propose the very thing I am trying to steer clear of.

Edit: This was flagged as duplicate. If the person flagging would have read the sentence below the question, I preemptively explained how it wasn't a duplicate. The linked question was the one I read previously and DID not help.

bblocs3141
  • 133
  • 2
  • 12
  • Possible duplicate of [onClick doesn't render new react component.](https://stackoverflow.com/questions/33840150/onclick-doesnt-render-new-react-component) – Mario Nikolaus Nov 22 '17 at 17:17
  • What you're trying to do there is illogical. An event describes what _happens_ when an action takes place. A component isn't something _happening_. Please provide a larger example of the component you want to add this to so people can show you how you can modify it to accomplish what you're trying to do. – JLRishe Nov 22 '17 at 17:32

1 Answers1

1

You have more than one solution for cross app notification system and they rely on Portals.

Bind handle to onClick and from handler call some notification component.

This one is fairly simple:

https://github.com/k4wo/react-notify

Mario Nikolaus
  • 2,346
  • 1
  • 21
  • 28
  • I would have liked to make it myself, but if the complex parts of it are already handled, then I'll take it! – bblocs3141 Nov 22 '17 at 19:10