question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow notifications to accept a title, body, and CTA

See original GitHub issue

Proposal

I’m proposing a change to the Notification component to allow rendering a title, body, and a CTA.

Approaches

Currently, the Notification component is called like so:

Notification.success('Text content of notification (string)', {
  duration: 6000 (int)
  canClose: true (boolean)
})

I can think of two approaches to achieve this:

1. Change the text to accept any node

Example usage:

const message = (
  <React.Fragment>
    <Heading>Notification title</Heading>
    <Paragraph>Some notification body copy</Paragraph>
    <TextLink href="#">Some CTA</TextLink>
  </React.Fragment>
);

Notification.success(message, {
  duration: 6000 (int)
  canClose: true (boolean)
})

Pros:

  • Minimal changes required
  • Uses exactly the same API to render content as before

Cons:

  • Could end up with many different variations
  • Need to refer to an example to know how to best construct message (could create NotificationTitle/NotificationBody/NotificationCta components though)

2. Add explicit props

Example usage:

const message = (
Notification.success('Body text content of notification (string)', {
  title: 'Message title' (string),
  cta: {
    label: 'CTA title (string)',
    action: '() => {blah} (function)'
  }
  duration: 6000 (int)
  canClose: true (boolean)
})

Pros:

  • Complete control over how component renders
  • TypeScript will show API usage hints

Cons:

  • Slightly confusing API (mix of strinng for body and settings object for title and CTA)
  • Slightly more involved changes needed

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
suevalovcommented, Mar 18, 2020

FYI, all notifications methods are exposed to UI Extension SDK so we shouldn’t do breaking changes.

What about the following:

Notification.success('Hello world!', {
  render: ({ message, onClose }) => (
     <div><h1>{message}</h1><button onClick={onClick}>CLOSE ME!</button></div>
  )
})
1reaction
m10lcommented, Mar 18, 2020

@burakukula Thanks for taking a look, I’m leaning towards option 2 too as it’s a bit more foolproof

@gui-santos This would be a lot nicer, but, if we broke the current API where you pass a string and an options object it would be a breaking change. Could possibly add it as an option in the options object too though

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declaring Your Actionable Notification Types - Apple Developer
Declare one or more notification categories at launch time from your iOS app. · Assign appropriate actions to your notification categories. · Handle...
Read more >
5 Ways Of User Engagement With Push Notification CTAs - VWO
Increase push notification user engagement with call to action buttons. Here are some examples on how to use this industry wise.
Read more >
10 Effective Push Notification Examples and Why They Work
This message title is followed by the notification's body copy, which gives a quick and dirty pitch for why the user needs the...
Read more >
Behind Web Push Notifications: What Marketers Need to Know
web push notification. ... These notifications allow you to send outreach that typically includes a title, body copy, a CTA, action buttons, and...
Read more >
An Advanced Guide to Mobile Push Notifications (Best ...
Furthermore, the title, body text, CTA, and thumbnail (when allowed) need to be engaging and entice each user to complete the conversion ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found