<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Noraiz Sardar on Medium]]></title>
        <description><![CDATA[Stories by Noraiz Sardar on Medium]]></description>
        <link>https://medium.com/@noraizsardar?source=rss-6645b27b24b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AxdCX8D3X_Kmkt49RVGVYw.jpeg</url>
            <title>Stories by Noraiz Sardar on Medium</title>
            <link>https://medium.com/@noraizsardar?source=rss-6645b27b24b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:13:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@noraizsardar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An imperative way to display messages in React MUI Application]]></title>
            <link>https://medium.com/red-buffer/an-imperative-way-to-display-messages-in-react-mui-application-b6e1b2699a82?source=rss-6645b27b24b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6e1b2699a82</guid>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[notifications]]></category>
            <dc:creator><![CDATA[Noraiz Sardar]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 11:29:06 GMT</pubDate>
            <atom:updated>2023-03-16T11:29:06.560Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Convenient Way to Display Messages in React Apps</h3><p>I work in React often to build the front-end of my applications which means I have a choice of choosing from hundreds of UI libraries. One of our current projects is based around insurance and litigation technology. The application was fairly complex hence it had complicated user flows and a lot of reusable components. So after some due diligence and careful requirement analysis, we decided to use Material UI (MUI) to build the front-end of our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IG-f1Af1kZHbd4CZRMhf7Q.png" /></figure><p>Coming from <a href="https://ant.design/">Ant Design</a> system to MUI, at first it feels like a lot of scratch code needs to be written to achieve a simple task e.g., forms - with no out-of-the-box component to work with forms. An interesting habit I developed with Ant was using an imperative style of writing simple logic like using <em>useMessage</em>, <em>useNotification</em> hooks to show messages and notifications. But MUI does not provide any out-of-the-box solution. After a bit of googling, I came across a library <a href="https://www.npmjs.com/package/notistack">notistack</a> that lets us achieve this style. But <strong>bundlephobia</strong> is a thing! And I want to reduce my module’s footprint as well. With that in mind, I decided to make a bare-bone imperative API to achieve this task.</p><p>I created a simple component called AppContext, which resides in the src directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ldl4hHkUphiSijpq97m_iw.png" /></figure><p>This will show the snackbar component whichever component calls the useMessage hook. Check the code below for useMessage hook.</p><figure><img alt="Code for useMessage hook" src="https://cdn-images-1.medium.com/max/1024/0*R04Qfz2gmeOrhil4" /><figcaption>src/custom/hooks/use-message.tsx</figcaption></figure><p>This is a vanilla version of the useMessage hook. You can customise it as much as you want with passing parameters, that extend <a href="https://mui.com/material-ui/api/snackbar/#props"><em>SnackbarProps</em></a>. Now you can call this hook anywhere in your component like this:</p><figure><img alt="using useMessage hook" src="https://cdn-images-1.medium.com/max/1024/0*L2czMC0CQ6sdnHrU" /><figcaption>src/page/use-invitation-form.tsx</figcaption></figure><p>You must have noticed that we are using Redux store to manage our snackbar display logic, now let’s look at how we have configured it with Redux.</p><figure><img alt="redux configuration in AppContextSlice" src="https://cdn-images-1.medium.com/max/1024/0*ZAKNQ7GLiYCzBrs6" /><figcaption>src/store/app-context-slice.tsx</figcaption></figure><p>Finally, we have added AppContext component in our root component like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KeB7r3VcfuXFga_Z" /><figcaption>src/index.tsx</figcaption></figure><p>This is a simple and intuitive way to create an imperative style API using React hooks to display messages. An interesting fact about the AppContext component, you can use the provider pattern in React and wrap the app component inside AppContext. I didn’t do it to avoid confusion, since Context API also wraps the app component and we are using Redux. You can also add hooks to manage open dialog boxes, handle async logics inside AppContext and keep the individual components clean and it will ensure the reusability as well.</p><p><em>Noraiz is a software engineer at </em><a href="http://redbuffer.ai/"><em>Red Buffer.</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6e1b2699a82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/red-buffer/an-imperative-way-to-display-messages-in-react-mui-application-b6e1b2699a82">An imperative way to display messages in React MUI Application</a> was originally published in <a href="https://medium.com/red-buffer">Red Buffer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>