<?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 Martina Carter on Medium]]></title>
        <description><![CDATA[Stories by Martina Carter on Medium]]></description>
        <link>https://medium.com/@martinacarter?source=rss-f4c0dea9da09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ebKHO53dv9JwNBOvk2_SLQ.png</url>
            <title>Stories by Martina Carter on Medium</title>
            <link>https://medium.com/@martinacarter?source=rss-f4c0dea9da09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 16:59:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@martinacarter/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[Persist Application Data with Local Storage]]></title>
            <link>https://javascript.plainenglish.io/persisting-data-using-local-storage-5820d2361990?source=rss-f4c0dea9da09------2</link>
            <guid isPermaLink="false">https://medium.com/p/5820d2361990</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Martina Carter]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 17:47:15 GMT</pubDate>
            <atom:updated>2021-02-23T15:12:11.805Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lxYm_ntYFiwYm1uy5FFaw.jpeg" /></figure><p>This article is for those getting started with learning to build web applications with HTML, CSS and JavaScript. If you want to store some data to a web application without getting into server-side code and databases, I will show you how you can persist your data using local storage.</p><p>Before I explain what local storage is, we must first take a look at the window object.</p><h3>The Window Object</h3><p>The window object represents a browser window that contains a DOM document. This object is created automatically by the browser. It contains properties and methods that we can use to control or manipulate the browser using our JavaScript code.</p><h3>What is Local Storage?</h3><p>Local storage is property of the window object. It returns a reference to the Storage object on a web page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*-ZRfvtU9tQ1kxV6GTrzcqQ.png" /></figure><p>If you look into the window object in the browser’s console, there you’ll find the local storage API with methods like getItem and<strong> </strong>setItem. These are the functions we will use in our upcoming example.</p><p>Local storage provides basic CRUD operations and allows you persist information in the computer’s browser. This prevents user-specific information from being lost without requiring the server to store it in a central database. Let’s say we created a simple web application using HTML that took input from the user and displayed it in the body of the page. If we refresh the page, the data that was displayed in the body of the page would disappear. Since standard HTML pages are static, a refresh would cause the page to revert to its original structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*yRUyjKZ3C9yrJlbWpEm4Dw.png" /></figure><p>When we use local storage, the data saved will persist in the browser until you manually clear it out in the browser settings, or by clearing it out programmatically. That means that data will persist even after a refresh or if the browser is closed and reopened.</p><p>The data is stored in key-value pairs and the value must be a String. You can still save values like arrays or any other object, but you can use JSON.stringify to convert it to a string and then JSON.parse to change it back when you need to use it. Let’s look at our example.</p><h3>Example Web App Using Local Storage</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*LMP6P1X2CNc-N08ROKDOkA.gif" /></figure><p>I’ve created a page to demonstrate how to use local storage to persist some data. The page allows a user to post and delete tweets.</p><p>Using local storage, we’re able to persist the tweets to memory, so even if we refresh or leave the browser, the tweets will still be there unless we delete them. Let’s take a look at the functionality that brings this to life.</p><h4>What we will cover in the example:</h4><ul><li>Add a tweet to the page</li><li>Remove tweet from page</li><li>Save tweet to local storage</li><li>Retrieve tweets from local storage</li><li>Remove tweet from local storage</li></ul><h3>Adding Tweets</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b415ceb0d28b9be66c52c9be2ddb755/href">https://medium.com/media/7b415ceb0d28b9be66c52c9be2ddb755/href</a></iframe><p>Here we have an event listener to listen in on when a user posts a tweet. First we’ll add the tweet to the list of tweets on page and then we will save the data using local storage.</p><p>The add tweet function takes in the text value of the tweet from the input field. First we create a list item. Each list item will have the following:</p><ul><li>Profile image</li><li>Name and handle</li><li>Time when tweet was posted</li><li>Tweet content</li><li>Trash icon to delete a tweet</li><li>Other interactive icons</li></ul><p>Once we create the list item with the above content, we then add the list item to the top of our list of tweets.</p><h3>Removing Tweets</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/120ca659eb1d30fd1177a4c3b7e9a9a3/href">https://medium.com/media/120ca659eb1d30fd1177a4c3b7e9a9a3/href</a></iframe><p>To remove a tweet, the user must click the trash icon. Clicking the icon will fire an event listener to remove the tweet. The deleteTweet function takes in the corresponding list item and remove it from the list of tweets.</p><h3>Local Storage</h3><p>I’ve created a Storage class that will take care of adding, retrieving, and removing tweets from local storage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3c10d0d001871dddae33423f74f4d4a/href">https://medium.com/media/e3c10d0d001871dddae33423f74f4d4a/href</a></iframe><h4>Saving To Local Storage</h4><p>Once we’ve added a tweet to the list, we will save the content to local storage. To do that, we will retrieve and save any tweets that were previously added to storage in an array, push the new tweet inside the array, and then update our stored tweets with the newly updated array of tweets.</p><p>Like I’ve mentioned before, data is stored to local storage in key-value pairs and the value has to be a string. In this case we convert our array of tweets into a string and then update the value to storage.</p><h4>Retrieving From Local Storage</h4><p>To get the tweets, we check local storage using the key and parse the value that is returned to an array. If the item did not exist, then what we’ll have is an empty array.</p><h4>Removing From Local Storage</h4><p>To remove that tweet from local storage, first we get all the tweets from storage, iterate through the array of tweets and remove the item that matches the tweet value. Once we remove the item from the array, we update our tweets in storage.</p><h3>Conclusion</h3><p>As you can see, we were able to persist our data without any server-side code or having to deal with databases. Ultimately, for real world applications that would be a necessity, but using local storage can be helpful to those that are starting out with some basic front-end concepts.</p><p>Full Repo: <a href="https://github.com/martinacarter1/tweet-local-storage/tree/master">persist-tweets-with-local-storage</a></p><p><strong><em>Read more at </em></strong><a href="https://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5820d2361990" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/persisting-data-using-local-storage-5820d2361990">Persist Application Data with Local Storage</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating ag-Grid into your React application]]></title>
            <link>https://javascript.plainenglish.io/integrating-ag-grid-into-your-react-application-53f430a3ab05?source=rss-f4c0dea9da09------2</link>
            <guid isPermaLink="false">https://medium.com/p/53f430a3ab05</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ag-grid]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Martina Carter]]></dc:creator>
            <pubDate>Tue, 29 Dec 2020 15:24:27 GMT</pubDate>
            <atom:updated>2020-12-29T17:18:49.473Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NANHjCqTxUvequ6Abbi6BQ.png" /></figure><p>If you’re trying to learn how to incorporate ag-Grid into your React application, you’ve made it to the right place.</p><p>In this article, I will cover both the client-side and server-side implementations of ag-Grid. I will explain all the necessary parts, and how to integrate both implementations into a React application.</p><p>For those new to ag-Grid, it is a feature-rich JavaScript data grid that supports major JavaScript frameworks like React, Angular, and Vue.</p><p>I’ve linked some popular features listed in the ag-Grid documentation:</p><ul><li><a href="https://www.ag-grid.com/javascript-grid-row-styles/">Layout &amp; Styling</a></li><li><a href="https://www.ag-grid.com/javascript-grid-selection-overview/">Selection</a></li><li><a href="https://www.ag-grid.com/javascript-grid-filtering-overview/">Filtering</a></li><li><a href="https://www.ag-grid.com/javascript-grid-rendering-flow/">Rendering</a></li></ul><h3>Client Side Implementation</h3><p>The client-side implementation is pretty straightforward. Here is what we’ll need for the client-side implementation:</p><ul><li>Ag-Grid React Component</li><li>OnGridReady</li><li>GridOptions</li><li>ColumnDefs</li><li>RowData</li></ul><p>There is also one other thing we’ll add but <strong>DON’T WORRY,</strong> I will explain.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f20032bed64c4fc8144d622d3778458/href">https://medium.com/media/3f20032bed64c4fc8144d622d3778458/href</a></iframe><h4>OnGridReady</h4><p>The first prop we added was onGridReady , which is an event callback that provides the grid and column API. Here we’ve used it to set the state of the local gridApi variable, which we can use later to perform actions on the grid like getting a selected row.</p><h4>GridOptions</h4><p>The gridOptions is a <em>‘one stop shop’</em> for the entire interface into the grid. All the grid properties are available through this object. Here it points to GridConfig.gridConfig .</p><p>The following is the file I’ve created called GridConfig , which contains an object with some properties that are needed for the grid.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58ebabe182ca09dbdc64958835c8df7c/href">https://medium.com/media/58ebabe182ca09dbdc64958835c8df7c/href</a></iframe><blockquote>Note: It is not necessary to create a separate file for the grid. I’ve only done so to separate concerns</blockquote><h4>ColumnDefs</h4><p>As mentioned before, the columnDefs were necessary for the grid. It is a property which contains the headerName to be displayed and the field for the corresponding row data.</p><p>Through the gridOptions, we are setting the column definitions. We could have easily placed the rowData property here in the configuration file or added it directly as a prop.</p><h4>RowData</h4><p>The rowData is the property used to set the data to be displayed as rows in the grid.</p><h4>Getting the Data</h4><p>All that is left to explain is the getGridData function. It makes a GET request to a file in the public folder where I’ve added the data for the grid (<em>this can be replaced with a real endpoint</em>). Once the data is returned, we set the rowData to its result and the grid gets populated with that data.</p><h3>Server Side Implementation (Enterprise only)</h3><p>There are a few differences when using the server-side implementation of ag-Grid. First we will have to introduce some new props which are rowModelTypeand cacheBlockSize. We also have to provide a new mechanism to supply the grid with data.</p><p>When using the client-side row model implementation, all we had to do was supply the data to the rowData prop for the grid. However, this prop is only available for the client-side implementation.</p><p>When using the server-side row model implementation, applications are required to implement a datasource, which is used to supply data to the grid. This implementation must conform to the server-side data source interface.</p><p>The following snippet shows a simple datasource implementation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*wnc8lUq91MVyFH1ratb3HQ.png" /></figure><p>Here is our implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dad884259813e2345357b26fde377e7/href">https://medium.com/media/4dad884259813e2345357b26fde377e7/href</a></iframe><h4>RowModelType</h4><p>The rowModelType sets the strategy for how data will be loaded into the grid. this is set to clientSide by default.</p><h4>CacheBlockSize</h4><p>The cacheBlockSize property determines how much data to fetch per request</p><h4>Registering the Datasource</h4><p>Aside from the new props needed for the grid, there are some other new things we have to introduce:</p><ul><li>getRows(params)</li><li>params.successCallBack()</li><li>parms.api.setServerSideDataSource()</li></ul><p>The getRows(params) function is called when the grid requires data. Rows fetched from the server are supplied to the grid via params.successCallback(). The params.api.setServerSideDataSource() registers the datasource to the grid.</p><h4>Getting the Data</h4><p>In this getGridData function, we first make a GET request to the location in the public folder where the row data is located. Then, we use the returned data array to supply the grid with rows using params.successCallback() . Finally, we register the datasource using params.api.setServerSideDataSource() .</p><h3>Conclusion</h3><p>We’ve now covered two different strategies for loading row data into the grid. With the client-side implementation, the application loads the full set of data into the client and then passes it in its entirety to the grid. With the server-side implementation, the data is kept on the server and loaded into the grid in parts. What it comes down to is deciding which implementation is best for your application’s needs. For more information on ag-Grid and all it’s features, check out the <a href="https://www.ag-grid.com/documentation-main/documentation.php">official documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53f430a3ab05" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/integrating-ag-grid-into-your-react-application-53f430a3ab05">Integrating ag-Grid into your React application</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Setup Spring MVC With React]]></title>
            <link>https://javascript.plainenglish.io/how-to-setup-spring-mvc-with-react-ce2cc422a7e0?source=rss-f4c0dea9da09------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce2cc422a7e0</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Martina Carter]]></dc:creator>
            <pubDate>Tue, 08 Dec 2020 16:49:12 GMT</pubDate>
            <atom:updated>2021-05-02T11:34:08.972Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Setup Spring Boot With React</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5O1FACcBhAfHurv32nmXCw.png" /><figcaption><em>This tutorial will have set you up with a full stack project in 6 steps</em></figcaption></figure><p>I wanted to create a full stack project that had a simple backend with some data and a frontend to display it. That’s it.</p><p>The objective is not really to get into the details of CRUD operations, creating APIs or the other fundamentals concepts that come with developing a full stack application. It is to simply express the bare minimum of what is necessary to achieve communication between the two components.</p><p>What I will cover is how to:</p><ol><li><strong>Create a spring project for the backend using </strong><a href="https://start.spring.io/"><strong>spring initializr</strong></a></li></ol><ul><li>Create spring project</li><li>Create JPA entities that represent the model</li><li>Set up repository and store data to H2 database</li><li>Create a controller to act as a mediator between the view and the model</li></ul><p>2<strong>. Create a react project for the frontend using </strong><a href="https://reactjs.org/docs/create-a-new-react-app.html"><strong>create-react-app</strong></a></p><ul><li>Create react project</li><li>Fetch data from backend</li><li>Display info from returned request</li></ul><h3>Step 1. Create project using Spring Initializr</h3><p><a href="https://start.spring.io/">Spring Initializr</a> is a tool that generates a Spring Boot project. We simply choose our desired dependencies along a build (Maven or Gradle) and it will assemble a project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zlUomPAbl1d7bDf-J9wuYA.png" /></figure><p>Add the following dependencies:</p><ul><li>Spring Web</li><li>Spring Data JPA</li><li>H2 Database</li></ul><p>After clicking <strong>generate</strong>, the zip will be downloaded to the computer. The project can be unzipped to a desired location. Open the project inside the IDE.</p><h3>Step 2. Create entities</h3><p>Now that the project is set up, the first thing we will do is create our JPA entities.</p><p>As mentioned before, the objective of this project is to have our backend communicate with our frontend. We will create instances of our JPA entities that we will display on our frontend.</p><p><strong>What’s JPA? What’s an Entity?</strong></p><p>JPA stands for Java Persistence API, and is a collection of classes and methods to store data in a database.</p><p>An Entity represents a table to be stored in a database.</p><p>First we will create a class and it will contain some data attributes. We want to create instances of this class and display its data to our frontend. To do that we will create the object, store it in a database and when we load up our front end, that stored data will be fetched and displayed.</p><p>The problem is that we can’t just store plain old java objects to a database without facing some issues. With databases having relational objects represented in a tabular format and java objects represented in an interconnected graph format, mismatches can happen when storing and retrieving an object from the database.</p><p>JPA helps represent these java objects in the way that is necessary to correctly persist them to a database. So by adding @Entity above a class we tell JPA that this represents a table in the database and every instance created represents a row in the table.</p><pre>@Entity<br>@Table(name = &quot;ARTIST&quot;)<br>public class Artist {<br>    @Id<br>    @GeneratedValue(strategy = GenerationType.<em>AUTO</em>)<br>    private Long id;<br><br>    private String firstName;<br>    private String lastName;<br><br>    @JsonBackReference<br>    @OneToMany(mappedBy = &quot;artist&quot;, cascade = CascadeType.<em>ALL</em>)<br>    private Set&lt;Song&gt; songs = new HashSet&lt;&gt;();</pre><pre>    //constructors, getters, and setters<br>    //override toString<br>    //override equals and hashCode -for id field only                 <strong><br></strong><br>}</pre><h3><strong>Step 3. Setup the repository</strong></h3><p>Repositories are responsible for persistence and query operations on JPA entities.</p><pre>@Repository<br>public interface ArtistRepository extends JpaRepository&lt;Artist, Long&gt; {<br>}</pre><h3>Step 4. Load data</h3><p>Now what we need to do is create some objects and store them into our H2 database.</p><p>H2 database is a lightweight relational Java database that can be configured to run as in-memory database. We will use this to store our objects.</p><pre>@Component<br>public class DataBaseLoader implements CommandLineRunner {<br><br>    private final ArtistRepository artistRepository;<br>    private final SongRepository songRepository;<br><br>    public DataBaseLoader(ArtistRepository artistRepository, SongRepository songRepository) {<br>        this.artistRepository = artistRepository;<br>        this.songRepository = songRepository;<br>    }<br><br>    @Override<br>    public void run(String... args) throws Exception {<br><br>        Artist jt = new Artist(&quot;Justin&quot;, &quot;Timberlake&quot;);<br>        Song cryMeARiver = new Song(&quot;Cry Me a River&quot;);<br><br>        artistRepository.save(jt);<br>        cryMeARiver.setArtist(jt);<br>        songRepository.save(cryMeARiver);<br><br>    }<br>}</pre><blockquote>If you’re wondering, the answer is yes, I’m a very big fan of Justin Timberlake so this example seems fitting</blockquote><h3>Step 5. Setup the controller</h3><p>We have our data saved to our in-memory database. Now we create the rest controller, which is responsible for returning the request data to the defined request handler method.</p><pre>@RestController<br>@RequestMapping(&quot;/api&quot;)<br>public class SongController {<br><br>    @Autowired<br>    private SongService songService;<br><br>    public SongController(SongService songService) {<br>        this.songService = songService;<br>    }<br><br>    @GetMapping(&quot;/songs&quot;)<br>    public List&lt;Song&gt; getAllSongs(){<br>      List&lt;Song&gt; result = songService.getAllSongs();<br>        return result;<br>    }<br>}</pre><p>When we run the spring application, a tomcat server is spun up on localhost:8080 . In our controller we create a method to grab all the songs from the database and return it. Using @GetMapping(&quot;/songs&quot;) we are saying to call the function when that endpoint receives a request. There’s also a @RequestMapping(&quot;/api&quot;) specifying the default for our requests. To retrieve all the songs, the full url is localhost:8080/api/songs</p><h3>Step 6. Setup the frontend react app</h3><p>create-react-app is a tool that generates a basic react project so that initial setup and configuration can be avoided.</p><p>Navigate to a location using the command line to save the frontend project.</p><p><em>If you’re not familiar with command line check this link on </em><a href="https://riptutorial.com/cmd/example/8646/navigating-in-cmd"><em>navigating in cmd</em></a><em>.</em></p><p>Run the following command to create a react app.</p><pre>npx create-react-app app-name-here<br>cd app-name-here<br>npm start</pre><p>Once the app is set up we will render the sample data we saved in our database. To do that we will fetch the data using the same path from our controller const response = await fetch(&#39;/api/songs&#39;)</p><p>To render the data we will save the response body from the request and render it a component</p><pre>&lt;Card bg=&#39;light&#39;style={{width:&#39;18rem&#39;}}&gt;</pre><pre>&lt;Card.Header&gt;{song.title}&lt;/Card.Header&gt;</pre><pre>&lt;Card.Body&gt;</pre><pre>&lt;Card.Title&gt;{song.artists}&lt;/Card.Title&gt;</pre><pre>&lt;/Card.Body&gt;</pre><pre>&lt;/Card&gt;</pre><p>By default the frontend instance is served on localhost:3000 . Our spring app is served on localhost:8080 so now all we have to do is tell our frontend that our requests should go to localhost:8080 . We do this by adding &quot;proxy&quot;:”http://localhost:8080 to our package.json and that’s it!</p><p>We’ve completed the objective and now have our backend connected and communicating to our frontend.</p><p>Full Repo: <a href="https://github.com/martinacarter1/springmvc-react/tree/master">springmvc-react</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce2cc422a7e0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-setup-spring-mvc-with-react-ce2cc422a7e0">How To Setup Spring MVC With React</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>