<?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 Haidi Zakelšek on Medium]]></title>
        <description><![CDATA[Stories by Haidi Zakelšek on Medium]]></description>
        <link>https://medium.com/@haidizakelek?source=rss-87d25e194625------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DiMDUV88icZqSDpIZP9GpQ.jpeg</url>
            <title>Stories by Haidi Zakelšek on Medium</title>
            <link>https://medium.com/@haidizakelek?source=rss-87d25e194625------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 10:21:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haidizakelek/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[Advanced Redux Patterns]]></title>
            <link>https://medium.com/@haidizakelek/advanced-redux-patterns-00837555bdf3?source=rss-87d25e194625------2</link>
            <guid isPermaLink="false">https://medium.com/p/00837555bdf3</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Haidi Zakelšek]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 09:35:06 GMT</pubDate>
            <atom:updated>2024-06-24T09:35:06.550Z</atom:updated>
            <content:encoded><![CDATA[<p>Redux is a powerful state management library commonly used with React to manage application state in a predictable and efficient way. While many developers are familiar with its basic concepts — such as actions, reducers, and the store — there is a wealth of advanced patterns and techniques that can elevate your Redux skills to the next level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZdGzj-wNIQuxLrPPozC0pg.png" /></figure><p>This article aims to guide you through these advanced Redux patterns, helping you tackle complex state management challenges.</p><h3><strong>Prerequisites:</strong></h3><ul><li>solid understanding of React,</li><li>Redux fundamentals and</li><li>JavaScript ES6+.</li></ul><h3><strong>Brief Overview of Redux</strong></h3><p>Redux is a state management library for JavaScript applications, commonly used with React. It provides a centralized store to hold the state of the entire application, ensuring a single source of truth. In Redux, state updates are predictable and traceable through a strict unidirectional data flow:</p><ul><li><strong>actions</strong> are dispatched to describe changes,</li><li><strong>reducers</strong> specify how the state transitions based on these actions, and -</li><li><strong>the store</strong> manages the <strong>state</strong> and allows components to subscribe to updates.</li></ul><p>This architecture helps in managing complex state logic, making applications easier to debug and test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*0TOBMnLBg6gr-CMPiia2kg.png" /><figcaption>Source: <a href="https://redux.js.org/tutorials/fundamentals/part-1-overview">https://redux.js.org/tutorials/fundamentals/part-1-overview</a></figcaption></figure><h3><strong>Normalizing State Shape</strong></h3><p>When managing complex and nested state in Redux, normalizing the state shape can significantly simplify updates and improve performance. Normalization involves restructuring your state to reduce redundancy and ensure that each piece of data is stored in one place.</p><p>How to Normalize State Shape</p><ul><li><strong>Flatten Nested Data</strong>: Convert nested structures into a flat structure using IDs as references.</li><li><strong>Use Entities and IDs</strong>: Store entities (e.g., users, posts) by their IDs in separate objects.</li><li><strong>Define Relationships</strong>: Maintain arrays of IDs to define relationships between entities.</li></ul><pre>//NON-NORMALIZED SHAPE<br>interface User {<br>    id: number;<br>    name: string;<br>  }<br>  <br>  interface Comment {<br>    id: number;<br>    text: string;<br>    commenter: User;<br>  }<br>  <br>  interface Post {<br>    id: number;<br>    title: string;<br>    author: User;<br>    comments: Comment[];<br>  }<br>  <br>  interface State {<br>    posts: Post[];<br>  }<br>  <br>  const state: State = {<br>    posts: [<br>      {<br>        id: 1,<br>        title: &#39;First Post&#39;,<br>        author: {<br>          id: 1,<br>          name: &#39;Author One&#39;<br>        },<br>        comments: [<br>          {<br>            id: 1,<br>            text: &#39;Great post!&#39;,<br>            commenter: {<br>              id: 2,<br>              name: &#39;Commenter One&#39;<br>            }<br>          }<br>        ]<br>      }<br>    ]<br>  };</pre><pre>//NORMALIZED STATE<br>interface User {<br>  id: number;<br>  name: string;<br>}<br><br>interface Comment {<br>  id: number;<br>  text: string;<br>  commenterId: number;<br>}<br><br>interface Post {<br>  id: number;<br>  title: string;<br>  authorId: number;<br>  commentIds: number[];<br>}<br><br>interface NormalizedState {<br>  users: { [id: number]: User };<br>  comments: { [id: number]: Comment };<br>  posts: { [id: number]: Post };<br>}<br><br>const normalizeState = (state: State): NormalizedState =&gt; {<br>  const users: { [id: number]: User } = {};<br>  const comments: { [id: number]: Comment } = {};<br>  const posts: { [id: number]: Post } = {};<br><br>  state.posts.forEach(post =&gt; {<br>    users[post.author.id] = post.author;<br>    posts[post.id] = {<br>      id: post.id,<br>      title: post.title,<br>      authorId: post.author.id,<br>      commentIds: post.comments.map(comment =&gt; comment.id)<br>    };<br>    post.comments.forEach(comment =&gt; {<br>      users[comment.commenter.id] = comment.commenter;<br>      comments[comment.id] = {<br>        id: comment.id,<br>        text: comment.text,<br>        commenterId: comment.commenter.id<br>      };<br>    });<br>  });<br><br>  return { users, comments, posts };<br>};<br><br>const state: State = {<br>  posts: [<br>    {<br>      id: 1,<br>      title: &#39;First Post&#39;,<br>      author: {<br>        id: 1,<br>        name: &#39;Author One&#39;<br>      },<br>      comments: [<br>        {<br>          id: 1,<br>          text: &#39;Great post!&#39;,<br>          commenter: {<br>            id: 2,<br>            name: &#39;Commenter One&#39;<br>          }<br>        }<br>      ]<br>    }<br>  ]<br>};<br><br>const normalizedState: NormalizedState = normalizeState(state);<br><br>console.log(normalizedState);</pre><h3>Redux Middleware</h3><p>Middleware in Redux <strong>is a function that sits between the action being dispatched and the action reaching the reducer</strong>. It provides a third-party extension point between dispatching an action and the moment it reaches the reducers. Middleware can intercept actions, process them, and either modify them or dispatch new actions. This makes middleware a powerful tool for handling various side effects and enhancing the capabilities of your Redux store.</p><p>As mentioned above, redux middleware works by wrapping the `dispatch` function. When an action is dispatched, it first passes through the middleware chain before reaching the reducers. Each <strong>middleware function</strong> <strong>receives the `store`’s `dispatch` and `getState` methods</strong>, allowing it to interact with the state and dispatch new actions.</p><p>The basic structure of a middleware function looks like this:</p><pre>const middleware = store =&gt; next =&gt; action =&gt; {<br>  // Middleware logic here<br>  return next(action);<br>};</pre><p>Here’s a simple example of custom middleware to log actions and state changes:</p><pre>const loggerMiddleware = store =&gt; next =&gt; action =&gt; {<br>  console.log(&#39;Dispatching action:&#39;, action);<br>  console.log(&#39;State before action:&#39;, store.getState());<br>  <br>  const result = next(action);<br>  <br>  console.log(&#39;State after action:&#39;, store.getState());<br>  <br>  return result;<br>};</pre><p>To use this custom middleware, apply it when creating the Redux store using applyMiddleware from redux.</p><pre>import { createStore, applyMiddleware } from &#39;redux&#39;;<br>import rootReducer from &#39;./reducers&#39;;<br><br>const store = createStore (<br>  rootReducer,<br>  applyMiddleware(loggerMiddleware)<br>);</pre><p>When you dispatch actions, the logger middleware will log the action and state changes.</p><pre>store.dispatch({ type: &#39;INCREMENT&#39; });<br>store.dispatch({ type: &#39;DECREMENT&#39; });</pre><p>Output in the console might look like this.</p><pre>Dispatching action: { type: &#39;INCREMENT&#39; }<br>State before action: { count: 0 }<br>State after action: { count: 1 }<br><br>Dispatching action: { type: &#39;DECREMENT&#39; }<br>State before action: { count: 1 }<br>State after action: { count: 0 }</pre><h3>Redux Toolkit with Slices and Thunks</h3><p>Redux Toolkit simplifies the process of writing Redux logic by providing a set of tools and best practices. It encourages using slices and thunks to manage state and asynchronous logic effectively.</p><h4><strong>Key Concepts</strong></h4><ol><li><strong>Slices</strong>: A slice is a collection of Redux reducer logic and actions for a single feature of your application. Each slice manages a portion of the application’s state.</li><li><strong>Thunks</strong>: Thunks are a way to write async logic that interacts with the Redux store. They allow you to dispatch actions and access the state.</li></ol><h4>Example: Todo Application with Async Data Fetching</h4><p>Let’s create a simple todo application that demonstrates these concepts.</p><h4>1. Setting Up the Project</h4><p>First, install the necessary dependencies:</p><pre>npm install @reduxjs/toolkit react-redux</pre><h4>2. Create the Todo Slice</h4><p>Define a slice to manage the todos state and handle actions. We’ll use TypeScript for type safety.</p><pre>// features/todos/todosSlice.ts<br>import { createSlice, createAsyncThunk, PayloadAction } from &#39;@reduxjs/toolkit&#39;;<br><br>interface Todo {<br>  id: number;<br>  text: string;<br>}<br><br>interface TodosState {<br>  items: Todo[];<br>  status: &#39;idle&#39; | &#39;loading&#39; | &#39;succeeded&#39; | &#39;failed&#39;;<br>  error: string | null;<br>}<br><br>// Initial state<br>const initialState: TodosState = {<br>  items: [],<br>  status: &#39;idle&#39;,<br>  error: null,<br>};<br><br>// Thunk to fetch todos from an API<br>export const fetchTodos = createAsyncThunk&lt;Todo[]&gt;(<br>  &#39;todos/fetchTodos&#39;,<br>  async () =&gt; {<br>    const response = await fetch(&#39;/api/todos&#39;);<br>    const data = await response.json();<br>    return data;<br>  }<br>);<br><br>const todosSlice = createSlice({<br>  name: &#39;todos&#39;,<br>  initialState,<br>  reducers: {<br>    todoAdded: (state, action: PayloadAction&lt;Todo&gt;) =&gt; {<br>      state.items.push(action.payload);<br>    },<br>  },<br>  extraReducers: (builder) =&gt; {<br>    builder<br>      .addCase(fetchTodos.pending, (state) =&gt; {<br>        state.status = &#39;loading&#39;;<br>      })<br>      .addCase(fetchTodos.fulfilled, (state, action: PayloadAction&lt;Todo[]&gt;) =&gt; {<br>        state.status = &#39;succeeded&#39;;<br>        state.items = action.payload;<br>      })<br>      .addCase(fetchTodos.rejected, (state, action) =&gt; {<br>        state.status = &#39;failed&#39;;<br>        state.error = action.error.message || &#39;Failed to fetch todos&#39;;<br>      });<br>  },<br>});<br><br>export const { todoAdded } = todosSlice.actions;<br><br>export default todosSlice.reducer;</pre><h4>3. Configure the Store</h4><p>Set up the Redux store and integrate the todos slice.</p><pre>// app/store.ts<br>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import todosReducer from &#39;../features/todos/todosSlice&#39;;<br><br>const store = configureStore({<br>  reducer: {<br>    todos: todosReducer,<br>  },<br>});<br><br>export default store;<br>export type RootState = ReturnType&lt;typeof store.getState&gt;;<br>export type AppDispatch = typeof store.dispatch;</pre><h4>4. Create a React Component to Display Todos</h4><p>Create a React component that connects to the Redux store and fetches todos on mount.</p><pre>// features/todos/TodosList.tsx<br>import React, { useEffect } from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { RootState, AppDispatch } from &#39;../../app/store&#39;;<br>import { fetchTodos } from &#39;./todosSlice&#39;;<br><br>const TodosList: React.FC = () =&gt; {<br>  const dispatch: AppDispatch = useDispatch();<br>  const todos = useSelector((state: RootState) =&gt; state.todos.items);<br>  const status = useSelector((state: RootState) =&gt; state.todos.status);<br>  const error = useSelector((state: RootState) =&gt; state.todos.error);<br><br>  useEffect(() =&gt; {<br>    if (status === &#39;idle&#39;) {<br>      dispatch(fetchTodos());<br>    }<br>  }, [status, dispatch]);<br><br>  if (status === &#39;loading&#39;) {<br>    return &lt;div&gt;Loading...&lt;/div&gt;;<br>  }<br><br>  if (status === &#39;failed&#39;) {<br>    return &lt;div&gt;Error: {error}&lt;/div&gt;;<br>  }<br><br>  return (<br>    &lt;ul&gt;<br>      {todos.map((todo) =&gt; (<br>        &lt;li key={todo.id}&gt;{todo.text}&lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>};<br><br>export default TodosList;</pre><h4>5. Integrate the Component with the App</h4><p>Integrate the TodosList component into your main application component.</p><pre>import React from &#39;react&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;./app/store&#39;;<br>import TodosList from &#39;./features/todos/TodosList&#39;;<br><br>const App: React.FC = () =&gt; {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;TodosList /&gt;<br>    &lt;/Provider&gt;<br>  );<br>}<br><br>export default App;</pre><h4>Explanation</h4><ol><li><strong>Slices</strong>: The todosSlice encapsulates all logic related to todos, including actions, reducers, and state. This makes the code modular and easier to maintain.</li><li><strong>Thunks</strong>: The fetchTodos thunk handles asynchronous fetching of todos from an API. It dispatches actions to update the state based on the API response.</li><li><strong>Extra Reducers</strong>: Using extraReducers in the slice to handle actions generated by thunks allows you to keep your async logic organized within the slice.</li><li><strong>Store Configuration</strong>: The store is configured with the todos reducer, integrating it into the application’s state management.</li></ol><p>This pattern of using Redux Toolkit with slices and thunks provides a scalable and maintainable approach to managing complex state and asynchronous logic in Redux applications.</p><h3><strong>Common Pitfalls and How to Avoid Them</strong></h3><h4><strong>1. Overusing Redux</strong></h4><p><strong>Pitfall</strong>: Putting all application states in Redux, including the local UI state, which can lead to unnecessary complexity and boilerplate.</p><p><strong>Solution</strong>: Use Redux for global state that needs to be shared across components and use local state (e.g., via React’s useState) for component-specific state.</p><h4>2. <strong>Ignoring State Normalization</strong></h4><p><strong>Pitfall</strong>: Storing nested or denormalized data, leading to inefficient updates and difficulty in managing related data.</p><p><strong>Solution</strong>: Normalize the state shape using libraries like normalizr to manage nested relationships efficiently.</p><h4>3. <strong>Mutating State</strong></h4><p><strong>Pitfall</strong>: Accidentally mutating state in reducers, leading to unexpected bugs and issues with time-travel debugging.</p><p><strong>Solution</strong>: Always return new state objects in reducers. Use tools like Immer to simplify immutable updates.</p><pre>import produce from &#39;immer&#39;;<br><br>const reducer = (state, action) =&gt; {<br>  return produce(state, draft =&gt; {<br>    switch (action.type) {<br>      case &#39;ADD_TODO&#39;:<br>        draft.todos.push(action.payload);<br>        break;<br>      // other cases<br>    }<br>  });<br>};</pre><h4>4. <strong>Unoptimized Selectors</strong></h4><p><strong>Pitfall</strong>: Writing selectors that cause unnecessary re-renders by recalculating derived state on every state change.</p><p><strong>Solution</strong>: Use memoized selectors with libraries like reselect to ensure derived state is only recalculated when necessary.</p><pre>import { createSelector } from &#39;reselect&#39;;<br><br>const getTodos = state =&gt; state.todos;<br>const getFilter = state =&gt; state.filter;<br><br>export const getVisibleTodos = createSelector(<br>  [getTodos, getFilter],<br>  (todos, filter) =&gt; {<br>    switch (filter) {<br>      case &#39;SHOW_COMPLETED&#39;:<br>        return todos.filter(todo =&gt; todo.completed);<br>      case &#39;SHOW_ACTIVE&#39;:<br>        return todos.filter(todo =&gt; !todo.completed);<br>      default:<br>        return todos;<br>    }<br>  }<br>);</pre><h4>5. <strong>Complex Middleware Logic</strong></h4><p><strong>Pitfall</strong>: Writing overly complex middleware that is hard to maintain and debug.</p><p><strong>Solution</strong>: Keep middleware focused and modular. Delegate complex logic to thunks, sagas, or other abstractions where appropriate.</p><p>By understanding and avoiding these common pitfalls, you can harness the full power of Redux to build scalable, maintainable applications. Advanced patterns like state normalization, efficient selectors, and custom middleware can significantly improve the performance and maintainability of your Redux applications.</p><h3>Conclusion</h3><p>In this article, we delved into advanced Redux patterns to enhance your state management skills. Here’s a summary of the key points discussed:</p><ul><li><strong>Normalizing State Shape:</strong> Restructuring your state to reduce redundancy and improve performance by flattening nested data and using entities and IDs.</li><li><strong>Redux Middleware:</strong> Utilizing middleware to intercept actions, handle side effects, and enhance the Redux store’s capabilities.</li><li><strong>Redux Toolkit with Slices and Thunks:</strong> Simplifying Redux logic with slices to manage state and actions, and thunks for asynchronous logic and API interactions.</li><li><strong>Example Project:</strong> Demonstrated a Todo application that integrates these advanced patterns, highlighting the benefits of Redux Toolkit.</li><li><strong>Common Pitfalls:</strong> Avoiding overusing Redux for local state, ignoring state normalization, mutating state, unoptimized selectors, and complex middleware logic.</li></ul><p>By understanding and implementing these advanced patterns, you can build more scalable and maintainable Redux applications. For further reading, consider exploring the official Redux documentation and tutorials. I hope this was helpful.</p><p>Greetings,</p><p>Haidi</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00837555bdf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inspiring women in tech]]></title>
            <link>https://medium.com/codex/inspiring-women-in-tech-b19e0b797541?source=rss-87d25e194625------2</link>
            <guid isPermaLink="false">https://medium.com/p/b19e0b797541</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[stem]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[womenintechblog]]></category>
            <dc:creator><![CDATA[Haidi Zakelšek]]></dc:creator>
            <pubDate>Tue, 22 Nov 2022 13:53:31 GMT</pubDate>
            <atom:updated>2022-11-22T13:53:31.173Z</atom:updated>
            <content:encoded><![CDATA[<p>Article dedicated to women, who challenge the gender gap and the status quo in the tech industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tb6oACQgfJOzZjfA6t7vlg.png" /></figure><h3>Marissa Mayer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0DMKLGd2AuR_c_1_wu-UYQ.jpeg" /><figcaption>source: <a href="http://nbcnews.com/tech/tech-news/marissa-mayer-stepping-down-verizon-completes-yahoo-deal-n771556">nbcnews</a></figcaption></figure><p>Coming from Wisconsin and intending to become a pediatric neurosurgeon she enrolled at Standford University. Later on, she switched courses and ended up getting a Master’s degree in computer science. She became <strong>Google’s first female engineer</strong> and <strong>20th employee</strong>.</p><p>She had one of the <strong>key roles</strong> in the development of some of Google’s main futures, such as <strong>Google Search, Google Images, Google Product Search, Google Maps, iGoogle, Gmail</strong>, etc. She spent 13 years at the tech company, which prepared her for the next role as<strong> CEO of Yahoo!. </strong>In addition to that, in 2014 she was named as 16th most influential woman by Forbes 40 under 40.</p><h3><strong>Ruchi Sanghvi</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*1_q8RVS5OETqd6RUtGXQBw.jpeg" /><figcaption>source: <a href="https://economictimes.indiatimes.com/magazines/panache/when-joining-a-startup-dont-ask-what-position-what-role-paytms-ruchi-sanghvi/articleshow/48353782.cms">economictimes</a></figcaption></figure><p>Ruchi was raised in Pune, India. Her curiosity led her to Carnegie Mellon University, where she pursued her bachelor’s and master’s degrees in electrical computer engineering. She was the <strong>first woman engineer to be hired by Facebook</strong> in 2010. There, she participated in <strong>the development of core Facebook functionalities such as the news feed</strong> and in 2006 became a <strong>product lead for the Facebook platform</strong>.</p><p>In 2011 she quit Facebook and <strong>co-founded</strong> a stealth collaboration startup called <strong>Cove</strong> with Aditya Agarwal. The startup was sold to Dropbox a year later and made Ruchi <strong>Vice President of Operations at Dropbox</strong>. In 2015 she left Dropbox but remained in an advisory role there. After leaving Dropbox she <strong>founded South Park Commons. </strong>South Park Commons is a technical community and co-working space located in the South Park neighbourhood of San Francisco and has over 450 active members and alumni globally today.</p><h3>Fei-Fei Li</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWRlcB1oqO9Rq9tEyxxV3Q.png" /><figcaption>source: <a href="https://spectrum.ieee.org/computer-vision-leader-feifei-li-on-why-ai-needs-diversity">IEEE Spectrum</a></figcaption></figure><p>She graduated from Princeton with a Bachelor of Arts degree in physics, and from the California Institute of Technology with a PhD in computer science.</p><p>She’s currently a sequoia capital professor and co-director of the Stanford Institute for Human-Centered Artificial Intelligence (HAI). She focuses on <strong>cognitive and computational neuroscience</strong>, and <strong>machine learning </strong>to improve AI image recognition ability. This research led her to take a sabbatical from Stanford from January 2017 to September 2018, when she served as<strong> vice president of Google</strong> and <strong>chief scientist of AI and machine learning at Google Cloud</strong>.</p><h3>Reshma Saujani</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*EgEU4gxlYDdrND0Kp7E4lw.png" /><figcaption>source: <a href="https://time.com/collection/american-voices-2017/5088970/american-voices-reshma-saujani/">time</a></figcaption></figure><p>Unlike the rest of the women on this list, Resha didn’t study computer science or any other field related to it. She graduated from Harvard University and Yale Law School and in 2010, she became the first Indian-American woman to run for Congress.</p><p>However, she still influenced the tech industry in a big way. In 2012 she started the <strong>nonprofit called Girls Who Code</strong>. It aims to increase the number of women in the computer science field and currently supports 500.000 girls, women and nonbinary individuals who are learning how to code. They’re reaching girls around the world and are on track to close the gender gap in new entry-level tech jobs by 2030. Pretty impressive, right?</p><h3>Kimberly Bryant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VhGcS42t8LeBbiClI1r0LA.jpeg" /><figcaption>source: <a href="https://medium.com/r?url=https%3A%2F%2Fwww.sfchronicle.com%2Fvisionsf%2Farticle%2FKimberly-Bryant-Black-Girls-Code-founder-opens-10995066.php">sfchronicle</a></figcaption></figure><p>Another woman who did not initially start in the industry, but left a huge impact is Kimberly Bryant. She was motivated by the struggle to find a diverse computer programming course for her daughter in the Bay Area. She decided to take matters into her own hands and used her 401(k) to start <a href="https://www.blackgirlscode.com/">Black Girls Code</a> in 2011, which now has the mission of teaching a million girls of colour how to code by the year 2040.</p><h3>Support</h3><p>Wondering how you can support women in tech? You can get involved in the community or donate to communities and organisations that support women in STEM, such as <a href="https://give.girlswhocode.com/give/77372/#!/donation/checkout">GirlsWhoCode</a>, <a href="https://wearebgc.org/donate/">BlackGirlsCode</a>, <a href="https://www.womenwhocode.com/donate">WomenWhoCode</a>, <a href="https://girlsintech.org/donate">GirlsInTech</a> and <a href="https://girldevelopit.networkforgood.com/projects/124267-scholarship-campaign">GirlsDevelopIT</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b19e0b797541" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/inspiring-women-in-tech-b19e0b797541">Inspiring women in tech</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSR, should you use it?]]></title>
            <link>https://levelup.gitconnected.com/ssr-should-you-use-it-dec6a5366193?source=rss-87d25e194625------2</link>
            <guid isPermaLink="false">https://medium.com/p/dec6a5366193</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming-tips]]></category>
            <dc:creator><![CDATA[Haidi Zakelšek]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 11:56:54 GMT</pubDate>
            <atom:updated>2022-11-08T11:56:54.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Server-side rendering can be a double-edged sword. Read the article below to see whether or not is it right for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISQBXQsSZCeb3s7KXwCkfQ.png" /></figure><h3>Intro</h3><p>Since the dawn of the internet, we could render web pages on the server side. Back then websites were fairly simple, their intention was to inform the user. They were very little or not interactive at all. The way SSR works is that it fully renders the entire webpage and then returns the HTML file to the client to use. With small bundle sizes and static pages, that worked great for a while.</p><p>But with time, websites became web applications. They became a lot more complex. They enabled users to chat, share pictures and documents, shop etc. All in all, they became heavily interactive and this is where the SSR slowly started losing popularity and client-side rendering started taking the centre stage.</p><h3>CSR vs. SSR</h3><p>Client-side rendering is rendering a web page in the browser, and not on your website’s server. It is the default with most Javascript frameworks today. CSR requests an HTML file with links to the browser on the initial load. Javascript then fetches those links and assembles the webpage together. One of the main downsides of CSR is that, since all the burden is on the browser, it can quickly add seconds to rendering, which leads to poor user experience. CSR application also often struggle with good SEO results and can perform poorly on slow devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*36RpWYwtYjnHbbzJLWC5yg.png" /></figure><p>With SSR, the server fully renders the entire page and then sends an HTML document to the browser, which then displays the content of the website. This means that the content is available a lot sooner, which favourably affects SEO and indexing. On the other hand, one of the major drawbacks of SSR is security since there is a lot more communication between the server and the browser compared to CSR. More requests also means more expenses. SSR works great for static pages, but with more interactive and complex page content, frequent full page reloads and requests can actually result in poor performance and slower page rendering. SSR apps also trend to have larger HTML files due to embedded hydration state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8020cBDCFoX1rl__o5fjzw.png" /></figure><h3>Google crawler</h3><p>One of the main reasons developers decide to implement <strong>SSR</strong> is <strong>SEO</strong> and <strong>performance improvement</strong> and consequently, a <strong>better user experience</strong>. But to understand the relationship between SEO and SSR, let’s first look at how indexing works.</p><p>In this article, we’ll take Googlebot, or as more people know it google’s web crawler, as an example. Googlebot works in three stages:</p><ul><li>crawling,</li><li>rendering,</li><li>indexing.</li></ul><p>Googlebot gets a website via an HTTP request. Firstly, Googlebot checks robots.txt file to see whether or not URL is allowed. There is an option to <a href="https://developers.google.com/search/docs/crawling-indexing/googlebot">block</a> Googlebot from indexing your site. If that’s the case, it will not make an HTTP request and skip this URL. If not, Googlebot will crawl the website and parse its HTML. When Googlebot assets allow it, Chromium renders the page and executes Javascript. Googlebot then uses rendered page for indexing and again parses HTML and scans it for links that allow crawling. Then it sets those links in a queue and repeats the process. Result of this is an indexed webpage. This means that the entire process Googlebot goes through, determines how high on the results queue is your webpage going to appear.</p><h3>Conclusion</h3><p>So now, which one to choose? SSR or CSR? Often, web applications use both. They are often referred to as hybrid applications. Netflix, for example, uses a combination of SSR, React(this is a library so CSR is the default) and prefetching. It uses SSR for static pages and React and prefetching for the rest. I just read an <a href="https://medium.com/dev-channel/a-netflix-web-performance-case-study-c0bcde26a9d9">article</a> recently, about how they optimised their web application and one of the conclusions author came to is the following:</p><blockquote>The tradeoff Netflix decided to make is to server-render the landing page using React, but also pre-fetching React / the code for the rest of the signup flow while on it. This optimizes first load performance, but also optimizes the time to load for the rest of the signup flow, which has a much larger JS bundle size to download since it’s a single-page app.</blockquote><p>I hope this will help you make an easier decision. If you have any further question leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dec6a5366193" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/ssr-should-you-use-it-dec6a5366193">SSR, should you use it?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Options API vs. Composition API]]></title>
            <link>https://medium.com/codex/options-api-vs-composition-api-4a745fb8610?source=rss-87d25e194625------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a745fb8610</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[vue-3]]></category>
            <dc:creator><![CDATA[Haidi Zakelšek]]></dc:creator>
            <pubDate>Tue, 18 Oct 2022 15:03:07 GMT</pubDate>
            <atom:updated>2022-10-18T15:03:07.776Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re starting a new project in Vue 3 or if you’re still deciding whether or not to migrate an existing project to the latest Vue.js version, this article is for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpBrPVr7sTsIY_ocShru1g.png" /></figure><h3>Let’s get started</h3><p>Up until Vue 2, there was one way to create components in Vue, with the methodology now known as the Options API. With Vue 3, a new methodology was introduced called the Composition API and you might be wondering what the difference is? In this article we’ll take a look at how those two differ.</p><p>Let’s start with looking at a simple setup withOptions API:</p><pre>export default {<br>  data() {<br>    return {<br>      name: &#39;Vue 3 App&#39;,<br>    };<br>  },<br>  methods: {<br>    showTxt() {<br>      console.log(`this is ${this.name}`);<br>    },<br>  },<br>  mounted() {<br>    this.showTxt();<br>  },<br>};</pre><p>If we take a look at the code, we notice 3 things, that are the building blocks of the <a href="https://vuejs.org/api/options-state.html">Options API</a>:</p><ul><li><a href="https://vuejs.org/api/options-state.html#data"><strong>data:</strong></a><strong> </strong>a function that returns the initial reactive state for the component instance,</li><li><a href="https://vuejs.org/api/options-state.html#methods"><strong>methods:</strong></a> declares methods to be mixed into the component instance. Declared methods can be directly accessed on the component instance, or used in template expressions. Avoid using arrow functions when declaring methods, as they will not have access to the component instance via <em>this,</em></li><li><a href="https://vuejs.org/api/options-lifecycle.html#mounted"><strong>mounted:</strong></a> this is a <strong>lifecycle hook</strong>, the component is mounted when it’s been created and inserted into the DOM.</li></ul><p>Other common things we can run into with Options API and are not in the code above are:</p><ul><li><a href="https://vuejs.org/guide/components/props.html#props-declaration"><strong>props:</strong></a> components require explicit props declaration so that Vue knows what external props passed to the component should be treated as fallthrough attributes,</li><li><a href="https://vuejs.org/api/options-state.html#watch"><strong>watch</strong>:</a> declares watch callbacks to be invoked on data change. The watch option expects an object where keys are the reactive component instance properties to watch (e.g. properties declared via data or computed) — and values are the corresponding callbacks.</li></ul><p>Now let’s take a look at the same example, but using Composition API:</p><pre>export default {<br>  setup() {<br>    const name = ref(&#39;Vue 3 App&#39;);<br>    <br>    const showTxt = () =&gt; console.log(`This is ${name.value}`);<br>    <br>    onMounted(() =&gt; {<br>      showTxt();<br>    });<br>    <br>    return { name };<br>  },<br>};</pre><p>As we can see from the code, Composition API only uses <a href="https://vuejs.org/api/composition-api-setup.html"><strong>setup hook</strong> </a>to define the component, which means a lot less code. Another important part of the code is <strong>ref,</strong> which is what makes the data reactive. It returns an object with a value property.</p><h3>Code Sharing</h3><p>One of the biggest differences between Options API and Composition API is the way they implement code sharing. <strong>Options API</strong> has two ways of sharing code,<strong> mixins</strong> and <strong>renderless components</strong>. Mixins can be a bit tricky to use, because they make it hard to determine where parts of code come from.</p><p>According to the docs, mixins are a flexible way to distribute reusable functionalities for Vue components. A mixin object can contain any component options. When a component uses a mixin, all options in the mixin will be “mixed” into the component’s own options. Here is an example of a mixin:</p><pre>// define a mixin object<br>var myMixin = {<br>  created: function () {<br>    this.helloWorld()<br>  },<br>  methods: {<br>    helloWorld: function () {<br>      console.log(&#39;hello from my mixin!&#39;)<br>    }<br>  }<br>}<br><br>// define a component that uses this mixin<br>var Component = Vue.extend({<br>  mixins: [myMixin]<br>})</pre><p>However, using mixins can be <strong>difficult to debug and understand</strong> for new developers, especially when they’re dealing with global mixins. Their use can also lead to <strong>naming conflicts </strong>with components.</p><p>With <strong>Composition API, </strong>there is no need for mixins. Inside the setup hook, we can <strong>group parts of code by logical concern</strong>. Then, we can extract pieces of reactive logic and share them with other components.</p><p>Now let’s take a look at <strong>renderless components. </strong>A renderless component<strong> </strong>is a component that <strong>doesn’t render any of its own HTML</strong>. Instead, it only manages state and behaviour, which gives the parent component complete control over what should be rendered. That means, that if you move logic out of a UI component and into a renderless component, <strong>you can reuse it.</strong></p><h3>Composables</h3><p>Composition API also supports <strong>renderless components</strong>, in fact, it’s one of the things Composition API and Options API have in common. However, a major advantage of Composition API are <strong>composables</strong>. They are reusable pieces of code and thanks to them, we can write reactive code anywhere. We’re not bound to the scope of a Vue component anymore. Here is a simple example of counter composable:</p><pre>import { computed, ref } from &#39;vue&#39;;<br><br>export function count() {<br>  const counter = ref(0);<br>  const addOne = () =&gt; { counter.value += 1 };<br>  <br>  return {<br>    counter,<br>    addOne,<br>  };<br>}</pre><p>And here we can see, how to use it in a component.</p><pre>&lt;template&gt;<br>  &lt;div&gt;Count: {{ counter }}&lt;/div&gt;<br>  &lt;button @click=&quot;addOne&quot;&gt; <br>     +<br>  &lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>import { count } from &#39;../composables/counter-example&#39;;<br><br>export default {<br>  setup() {<br>    const {<br>      counter,<br>      addOne,<br>    } = count();<br><br>    return {<br>      counter,<br>      addOne,<br>    };<br>  },<br>};<br>&lt;/script&gt;</pre><p>Composables act as an external function that extracts reactive state and functionality to be used across several other components. They can alternatively be called composition functions. With composables, we can tell <strong>exactly where our reusable data and functions come from</strong>.</p><p>Another major advantage of Composition API is that it makes constants and dependencies available in the template:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>  &lt;button @click=&quot;create&quot;&gt;<br>   Save<br>  &lt;/button&gt;<br>&lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>import { create } from &#39;./services&#39;;<br><br>export default {<br>  setup() {<br>    return {<br>      create,<br>    };<br>  },<br>};<br>&lt;/script&gt;</pre><p>When doing the same thing using the Options API, it can feel awkward. You either have to add constants and dependencies to your data option or use the created hook to add non-reactive variables to the this context. Composition API saves us some trouble here, as we can simply export them from setup hook and make them available inside the template.</p><p>This about sums up the comparison and to conclude things, if you came to a point, where you decided to migrate to the latest version of Vue, as of reasons stated above, Composition API may be worth the trouble as it optimizes the code very nicely and will consequently give your app a better performance. If you are starting from scratch, Composition API would be recommended.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a745fb8610" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/options-api-vs-composition-api-4a745fb8610">Options API vs. Composition API</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple guide to Vue 3 routing]]></title>
            <link>https://medium.com/@haidizakelek/a-simple-guide-to-vue-3-routing-381a778a6062?source=rss-87d25e194625------2</link>
            <guid isPermaLink="false">https://medium.com/p/381a778a6062</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vuejs-3]]></category>
            <dc:creator><![CDATA[Haidi Zakelšek]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 16:19:11 GMT</pubDate>
            <atom:updated>2022-10-04T16:32:48.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vhb6e_hGsN0DssTCyvPenQ.png" /></figure><p>In this tutorial, I will show you how to set up routing for Vue 3 using Composition API, Vue Router 4 and Pokemon OpenAPI.</p><h3>Prerequisites</h3><ul><li>Yarn / npm,</li><li>VS Code or Webstorm,</li><li>basic knowledge of JavaScript and Vue.</li></ul><h3>Getting started</h3><p>So, let’s get started with our Vue.js Route<strong>r</strong> project by installing and creating a new Vue.js project. We need to have Node.js installed. Check if the node version is 10.6.0 or higher by running the following command:</p><pre>node -v</pre><p>If you don’t have it installed yet, you can download it <a href="https://nodejs.org/en/download/">here</a>. We will also be using <a href="https://github.com/vuejs/vue-cli">Vue CLI</a> to generate a new Vue.js project. You can install the it with the following command:</p><pre>yarn global add @vue/cli<br># OR<br>npm install -g @vue/cli</pre><p>Check if it is installed correctly by running:</p><pre>vue --version</pre><p>This should return the version of your Vue CLI. Now, let’s create our project!</p><p>Open up the terminal and type in the following command to create a new Vue project:</p><pre>vue create pokemon-app</pre><p>After creating a project, you will have to pick a package. For this tutorial we’ll user the one with Vue 3, babel, eslint as show in a picture below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*UWWJlI09SEK-PajLbMpSsA.png" /></figure><p>Now, let’s change the directory to the project folder:</p><pre>cd pokemon-app</pre><p>We start the project by using the following commands:</p><pre>yarn serve<br>#OR<br>npm run serve</pre><p>You can see the application running on <a href="https://localhost:8080/">http://localhost:8080</a>.</p><h3>Creating views</h3><p>Views are components that are shown when the user visits our page. We will create 3 views to navigate through. One with the list of all pokemons called PokemonList.vue, one with details of selected pokemon called PokemonDetails.Vue and on NotFound.vue. Now, lets move to the src folder using the following command:</p><pre>cd src</pre><p>Then create views folder:</p><pre>mkdir views</pre><p>After a folder is created. Add following files to it:</p><ul><li>PokemonList.vue,</li><li>PokemonDetails.vue,</li><li>NotFound.vue.</li></ul><p>In this project, we’ll use <a href="https://getbem.com/introduction/">BEM</a> naming convention standard and <a href="https://sass-lang.com/">Sass</a>. To install the latter, run the following command:</p><pre>yarn add sass-loader<br>#OR<br>npm install sass-loader</pre><p>The last thing we need to install is (you guessed it) the router. Install it by running the following command:</p><pre>yarn add vue-router@4<br>#OR<br>npm install vue-router@4</pre><h3>Creating router</h3><p>Now we need to create the router. Make sure you’re in the src directory and run the following command:</p><pre>mkdir router</pre><p>Then create index.js file inside the router folder and paste the following code:</p><pre>import { createRouter, createWebHistory } from &#39;vue-router&#39;;</pre><pre>const routes = [<br>    {<br>        path: &quot;/pokemons&quot;,<br>        name: &quot;AllPokemons&quot;,<br>        component: () =&gt; import(&#39;../views/PokemonList.vue&#39;)<br>    },<br>    {<br>        path: &quot;/pokemon/:name&quot;,<br>        name: &quot;PokemonDetails&quot;,<br>        component: () =&gt; import(&#39;../views/PokemonDetails.vue&#39;)<br>    },<br>    {<br>        path: &quot;/:catchAll(.*)&quot;,<br>        component: () =&gt; import(&#39;../views/NotFound.vue&#39;)<br>    },<br>]<br><br>const <strong><em>router </em></strong>= createRouter({<br>    history: createWebHistory(<strong><em>process</em></strong>.env.BASE_URL),<br>    routes<br>})<br><br>export default <strong><em>router</em></strong></pre><p>We imported <em>createRouter</em> and <em>createWebHistory</em> functions from Vue Router. These functions construct a router object and create a routing history user can go back to.</p><p>Firstly we notice a path to pokemon details has <strong>:name</strong> <strong>param</strong> in the path. Param is defined by <strong>: </strong>and<strong> </strong>can manipulate a route based on its value. When the route is matched, a value of its <em>params</em> is exposed as this.$route.params in every component. That kind of matching is what makes the <strong>routes dynamic</strong>.</p><p>We can also notice a pattern in the way routes a defined. It consists of route, name and component. In component, we didn’t call the component directly but used <strong>a dynamic import statement</strong> instead, because this is how <strong>lazy loading</strong> is implemented.</p><p>Let’s look at the difference:</p><pre>//REGULAR LOADING<br>{<br>    path: &quot;/pokemon/:name&quot;,<br>    name: &quot;PokemonDetails&quot;,<br>    component: PokemonDetails<br>}</pre><pre>//LAZY LOADING<br>{<br>    path: &quot;/pokemon/:name&quot;,<br>    name: &quot;PokemonDetails&quot;,<br>    component: () =&gt; import(&#39;../views/PokemonDetails.vue&#39;)<br>}</pre><p>With development, our code and routes can get complex and bundle size can increase. So instead of loading everything at once, lazy loading enables us to load the route only after it’s called. This can increase app performance and consequently improve user experience.</p><h3>Adding content</h3><p>Ok, now that we got that taken care of, let’s start with setting up PokemonList.vue file. If we take a look at Pokemon API documentation, we see <a href="https://pokeapi.co/api/v2/pokemon">https://pokeapi.co/api/v2/pokemon</a> returns an array of objects. Each object has two properties called name and url. In our template, we’ll only be showing the name. So let’s set up a template:</p><pre>&lt;template&gt;<br>  &lt;div&gt;    <br>    &lt;ul class=&quot;pokemon-list&quot;&gt;<br>      &lt;li class=&quot;pokemon-list__item&quot;&gt;<br>          &lt;span&gt; Name: &lt;/span&gt;<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import { ref } from &quot;vue&quot;;<br>export default {<br>  name: &#39;PokemonList&#39;,<br>  setup() {<br>    const apiUrl = &quot;https://pokeapi.co/api/v2/pokemon/&quot;;<br>    let allPokemonsList = ref([]);<br>    return {<br>      allPokemonsList,<br>    };<br>  },<br>}<br>&lt;/script&gt;<br>&lt;style lang=&quot;scss&quot; scoped&gt;<br>.pokemon-list {<br>  list-style: none;<br>  width: 50%;<br>   &amp;__item {<br>      background-color: lightgray;<br>      margin: 10px;<br>      padding: 10px;<br>      border-radius: 5px;<br>   }<br>}<br>&lt;/style&gt;</pre><p>Now that we have abasic template setup, we need to fetch the data from the API to populate the <em>allPokemonsList</em>. We do that by adding the following code to the script:</p><pre>&lt;script&gt;<br>import { <strong><em>onMounted</em></strong>, ref } from &quot;vue&quot;;<br>export default {<br>  name: &#39;PokemonList&#39;,<br>  setup() {<br>    const apiUrl = &quot;https://pokeapi.co/api/v2/pokemon/&quot;;<br>    let allPokemonsList = ref([]);<br>    <strong><em>onMounted</em></strong>(() =&gt; {<br>      fetchPokemons();<br>    });<br>    const fetchPokemons = () =&gt; {<br>      fetch(apiUrl)<br>          .then((response) =&gt; response.json())<br>          .then((data) =&gt; {<br>            allPokemonsList.value = data.results;<br>          });<br>    };<br>    return {<br>      allPokemonsList,<br>      fetchPokemons,<br>    };<br>  },<br>}<br>&lt;/script&gt;</pre><p>We added the <a href="https://vuejs.org/api/composition-api-lifecycle.html#onmounted"><strong>onMounted</strong></a> hook to the script. This is a Vue <strong>lifecycle hook</strong> and will call <em>fetchPokemons</em> method once the component is mounted(the component is mounted when it’s been created and inserted into the DOM).</p><p>Now, we also have to update the template to show fetched data. Here is an updated template:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;ul class=&quot;pokemon-list&quot;&gt;<br>      &lt;li v-for=&quot;pokemon in allPokemonsList&quot; :key=&quot;pokemon.name&quot;<br>          class=&quot;pokemon-list__item&quot;&gt;<br>        &lt;router-link :to=&quot;&#39;/pokemon/&#39; + pokemon.name&quot;&gt;<br>          &lt;span&gt; Name: {{ pokemon.name }}&lt;/span&gt;<br>        &lt;/router-link&gt;<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>We added a v-for loop that will go through all fetched pokemons and show their names. Instead of an anchor tag, we used Vue Router’s <strong>router-link</strong> component. The component has <strong>:to</strong> <strong>prop</strong>, which accepts key-value pairs. There are two methods of using the router-link component: the <strong>path property</strong>(the one we’re using) and <a href="https://router.vuejs.org/guide/essentials/named-routes.html"><strong>named routes</strong></a>.</p><p>Here is the difference:</p><pre>//USING PATH PROPERTY<br>&lt;router-link :to=&quot;&#39;/pokemon/&#39; + pokemon.name&quot;&gt;<br>     &lt;span&gt; Name: {{ pokemon.name }}&lt;/span&gt;<br> &lt;/router-link&gt;</pre><pre>//USING NAMED ROUTES<br>&lt;router-link :to=&quot;{ name: &#39;PokemonDetails&#39;, params: { name: pokemon.name }}&quot;&gt;<br>  &lt;span&gt; Name: {{ pokemon.name }}&lt;/span&gt;<br>&lt;/router-link&gt;</pre><p>The named routes approach needs two properties: name, for the name of the route and params, for any kind of params we’re passing to the route. Since we have a small number of routes updating the route name wouldn’t be an issue, but with more complex apps, changing URL name and then manually updating it wherever it’s used can be painful.</p><p>Now, to get back to the code, at this point your PokemonList.vue file should look like this:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;ul class=&quot;pokemon-list&quot;&gt;<br>      &lt;li v-for=&quot;pokemon in allPokemonsList&quot; :key=&quot;pokemon.name&quot;<br>          class=&quot;pokemon-list__item&quot;&gt;<br>        &lt;router-link :to=&quot;{ name: &#39;PokemonDetails&#39;, params: { name: pokemon.name }}&quot;&gt;<br>          &lt;span&gt; Name: {{ pokemon.name }}&lt;/span&gt;<br>        &lt;/router-link&gt;<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import { <strong><em>onMounted</em></strong>, ref } from &quot;vue&quot;;<br>export default {<br>  name: &#39;PokemonList&#39;,<br>  setup() {<br>    const apiUrl = &quot;https://pokeapi.co/api/v2/pokemon/&quot;;<br>    let allPokemonsList = ref([]);<br>    <strong><em>onMounted</em></strong>(() =&gt; {<br>      fetchPokemons();<br>    });<br>    const fetchPokemons = () =&gt; {<br>      fetch(apiUrl)<br>          .then((response) =&gt; response.json())<br>          .then((data) =&gt; {<br>            allPokemonsList.value = data.results;<br>          });<br>    };<br>    return {<br>      allPokemonsList,<br>      fetchPokemons,<br>    };<br>  },<br>}<br>&lt;/script&gt;<br>&lt;style lang=&quot;scss&quot; scoped&gt;<br>.pokemon-list {<br>  list-style: none;<br>  width: 50%;<br>   &amp;__item {<br>      background-color: lightgray;<br>      margin: 10px;<br>      padding: 10px;<br>      border-radius: 5px;<br>   }<br>}<br>&lt;/style&gt;</pre><p>Now we also need to add the code for PokemonDetails.vue:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;div class=&quot;pokemon-details&quot;&gt;<br>      &lt;h1&gt; {{ pokemonDetails.name }}&lt;/h1&gt;<br>      &lt;button class=&quot;back-btn&quot; @click=&quot;$router.back()&quot;&gt;Go back&lt;/button&gt;<br>      &lt;h2&gt;Abilities&lt;/h2&gt;<br>      &lt;ul class=&quot;pokemon-details__abilities&quot;&gt;<br>        &lt;li v-for=&quot;item in pokemonDetails.abilities&quot; :key=&quot;item.name&quot;&gt;<br>          &lt;span&gt;{{ item.ability.name }}&lt;/span&gt;<br>        &lt;/li&gt;<br>      &lt;/ul&gt;<br>      &lt;h2&gt;Moves&lt;/h2&gt;<br>      &lt;ul class=&quot;pokemon-details__moves&quot;&gt;<br>        &lt;li v-for=&quot;item in pokemonDetails.moves&quot; :key=&quot;item.name&quot;&gt;<br>          &lt;span&gt;{{ item.move.name }}&lt;/span&gt;<br>        &lt;/li&gt;<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>import { <strong><em>onMounted</em></strong>, ref } from &quot;vue&quot;;<br>import { useRoute } from &quot;vue-router&quot;;<br><br>export default {<br>  name: &#39;PokemonDetails&#39;,<br>  setup() {<br>    const apiUrl = &quot;https://pokeapi.co/api/v2/pokemon/&quot;;<br>    const route = useRoute();<br>    let pokemonDetails = ref({});<br>    <strong><em>onMounted</em></strong>(() =&gt; {<br>      fetchPokemonDetails();<br>    });<br>    const fetchPokemonDetails = () =&gt; {<br>      fetch(apiUrl + route.params.name)<br>          .then((response) =&gt; response.json())<br>          .then((data) =&gt; {<br>            pokemonDetails.value = data;<br>          });<br>    };<br>    return {<br>      pokemonDetails,<br>      fetchPokemonDetails,<br>    };<br>  },<br>}<br>&lt;/script&gt;<br>&lt;style lang=&quot;scss&quot; scoped&gt;<br>.pokemon-details {<br>  width: 30%;<br>  text-align: left;<br>  padding: 10px;<br><br>  &amp;__abilities {<br>    padding-left: 0;<br>    list-style: none;<br>  }<br>  &amp;__moves {<br>    padding-left: 0;<br>    list-style: none;<br>  }<br><br>  li {<br>    margin: 10px;<br>    padding: 10px;<br>    border-radius: 5px;<br>    border-bottom: 1px solid grey;<br>  }<br>}<br>&lt;/style&gt;</pre><p>It’s quite similar to the PokemonList.vue component, but if you’ve noticed, we added a little back button to the top of the component.</p><p>Now, we also need to add template to the NotFound.vue component:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;<br>      Sorry, this page doesn&#39;t exist or has been moved to another location<br>    &lt;/h1&gt;<br>  &lt;/div&gt;<br>&lt;/template</pre><p>And this is it. The app should be all set now. I hope this article will be of help to you.</p><p>Till next time 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=381a778a6062" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vuex or Pinia?]]></title>
            <link>https://medium.com/@haidizakelek/vuex-or-pinia-8bfbeda11339?source=rss-87d25e194625------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bfbeda11339</guid>
            <category><![CDATA[vuex]]></category>
            <category><![CDATA[pinia]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Haidi Zakelšek]]></dc:creator>
            <pubDate>Wed, 21 Sep 2022 19:02:46 GMT</pubDate>
            <atom:updated>2022-09-21T21:17:52.297Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will compare Vuex and Pinia, two popular state management libraries for Vue.js. Now, let’s get started, shall we?</p><h3>What is Vuex?</h3><p>Well, the documentation describes Vuex as a state management pattern and library for Vue.js. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated predictably. It consists of state, mutations and actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*KIoNyRO6s_52W68Y-0usJw.png" /></figure><p>Let’s setup a simple Vuex store. To install run the following commands in your terminal:</p><pre>npm install vuex@next --save<br># or with yarn<br>yarn add vuex@next --save</pre><p>To create the store, you call createStore method with an object containing state, mutations, actions and getters.</p><pre>const store = createStore({<br>    state () {<br>        return {<br>            count: 0<br>        }<br>    },<br>    mutations: {<br>        increment (state) {<br>            state.count++<br>        }<br>    },<br>    actions: {<br>        increment(context) {<br>            context.commit(&#39;increment&#39;)<br>        }<br>    },<br>    getters: {<br>        finalCount(state) {<br>            return state.count<br>        }<br>    }<br>})</pre><p><strong>State:</strong> It’s an object, which contains all the data and is accessible application-wide.</p><p><strong>Mutations: </strong>The only way to update data in the state is through a mutation. They are synchronous and recieve two arguments, current app state and payload needed to update the application.</p><p><strong>Actions: </strong>They are similar to mutations, the main difference being actions can be either synchronous or asynchronous. They don’t mutate the state directly but once dispatched, they call a mutation.</p><p><strong>Getters:</strong> Vuex allows us to define “getters” in the store. You can think of them as computed properties for stores.</p><p>Now that we have defined the store, we need to add it to the root Vue.js project file:</p><pre>import { createApp } from &#39;vue&#39;<br>import App from &#39;./App.vue&#39;<br>import {useStore} from &#39;./store&#39;<br>createApp(App).use(store).mount(&#39;#app&#39;)</pre><h3>What is Pinia?</h3><p>Pinia is a new, default and lightweight state management library for Vue 3. It allows you to share a state across components and pages and is becoming quite popular. Let’s get a closer look by setting up Pinia. To install it, run the following commands:</p><pre>yarn add pinia@next<br># or with npm<br>npm install pinia@next</pre><p>This version is compatible with Vue 3. If you are looking for a version compatible with Vue 2.x, check out <a href="https://github.com/posva/pinia/tree/v1">the </a><a href="https://github.com/posva/pinia/tree/v1">v1 branch</a>.</p><p>Now let’s setup basic pinia store.</p><pre>export const <strong><em>useCounterStore </em></strong>= defineStore(&#39;counter&#39;, {<br>    id: &#39;counter&#39;,                                                    <br>    state: () =&gt; {<br>        return { count: 0 }<br>    },<br>    getters: {<br>        tripleCount: (state) =&gt; state.count * 3<br>    },<br>    actions: {<br>        increment() {<br>            this.count++<br>        },<br>    },<br>})</pre><p>Firstly we see that we use defineStore function instead of createStore, that’s because the store is not created until It’s actually used. Each store needs a unique id to mount store in devtools. Similar to Vuex, Pinia uses state, actions and getters.</p><p><strong>State: </strong>is a central part of the store and a function that returns the initial state.</p><p><strong>Actions:</strong> are functions that have access to and can update state. They can be asynchronous.</p><p><strong>Getters:</strong> are functions which receive state as a first argument.</p><p>Now, all we have to do is add Pinia to the Vue.js project so that we can use its global object.</p><pre>import { createPinia } from &#39;pinia&#39;<br>app.use(createPinia())</pre><h3>Vuex vs. Pinia</h3><p>We can see that setup of both is fairly simple and according to Eduardo San Martin Morote, creator of and Pinia and part of the Vue.js core team, Pinia and Vuex have more similarities than differences:</p><p><em>Pinia tries to stay as close to Vuex’s philosophy as possible. It was designed to test out a proposal for the next iteration of Vuex and it was a success as we currently have an open RFC for Vuex 5 with </em><a href="https://github.com/vuejs/rfcs/discussions/270"><em>an API very similar</em></a><em> to the one used by Pinia. My personal intention with this project is to redesign the experience of using a global Store while keeping the approachable philosophy of Vue. I keep the API of Pinia as close as Vuex as it keeps moving forward to make it easy for people to migrate to Vuex or to even fusion both projects (under Vuex) in the future.</em></p><p>However, there are a few important distinctions:</p><ul><li>The biggest criticism Vuex gets, It’s for the complexity and similarity of mutation and action patterns. If we take a look at mutations and actions of the Vuex store, we see that the code is very similar, which can lead to <strong>boilerplate code</strong>. In Pinia <strong>mutations are removed.</strong></li><li>Pinia also has better<strong> typesciprt support </strong>and offers <strong>auto-completion</strong> for Javascript code.</li><li>It supports <strong>SSR</strong>, <strong>Composition API, Options API </strong>and<strong> webpack code splitting.</strong></li><li>Pinia offers <strong>implicit nesting</strong>, so you can easily import and use one store inside of another, with no more nested modules. You can even have circular dependencies of stores.</li><li>Pinia has It’s own set of <strong>devtools </strong>for eaiser debugging, however it does <strong>not offer support</strong> for debugging features like <strong>editing and time traveling</strong>, while Vuex does.</li><li>Pinia is <strong>extremely lightweight </strong>(weighing around 1KB).</li></ul><p>If you’re using Vuex at the time of reading this article, no worries, It is still supported and does not seem to be going anywhere anytime soon. However, if you’re thinking of starting a new project, according to the official documentation of Vue, It is recommended to use Pinia. I hope this article will help you make an easier decision going forward.</p><p>Till next time! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bfbeda11339" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>