<?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 Benny on Medium]]></title>
        <description><![CDATA[Stories by Benny on Medium]]></description>
        <link>https://medium.com/@benny_18022?source=rss-23d36d481dee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Benny on Medium</title>
            <link>https://medium.com/@benny_18022?source=rss-23d36d481dee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 15:56:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@benny_18022/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[Understanding React Query]]></title>
            <link>https://medium.com/bina-nusantara-it-division/understanding-react-query-11e56960e90c?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/11e56960e90c</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[tanstack-query]]></category>
            <category><![CDATA[fetch-api]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-query]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 17:01:51 GMT</pubDate>
            <atom:updated>2023-09-29T17:01:51.758Z</atom:updated>
            <content:encoded><![CDATA[<h4>Simplifying Data Fetching in React Applications</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slZR4US7-L7TkkIUB9cY9Q.jpeg" /><figcaption>Ferenc Almasi — unsplash.com</figcaption></figure><p>React Query is a powerful library developed by TanStack that simplifies data fetching and state management in React applications. It provides a straightforward way to manage remote data and keep it in sync with the UI. This article will introduce you to React Query, its key features, and how to get started using it in your React projects.</p><h3>What is React Query?</h3><p>React Query is a JavaScript library designed to simplify the complex task of data fetching and caching in React applications. It offers a set of hooks and utilities that enable you to manage data from various sources, including REST APIs, GraphQL, or even local state, effortlessly.</p><h3>Key Features</h3><ol><li><strong>Declarative Data Fetching:</strong> React Query promotes a declarative approach to data fetching. You define queries and mutations using hooks like useQuery and useMutation. This leads to cleaner and more organized code.</li><li><strong>Automatic Caching:</strong> React Query includes a built-in cache that stores query results. It automatically updates data when mutations occur, ensuring your UI remains consistent.</li><li><strong>Background Data Sync:</strong> It can automatically refetch data in the background, keeping your data fresh without manual intervention.</li><li><strong>Pagination and Infinite Scrolling:</strong> React Query provides utilities for handling pagination and infinite scrolling effortlessly.</li><li><strong>Optimistic Updates:</strong> You can implement optimistic updates with ease, making your app feel more responsive.</li></ol><h3>Getting Started with React Query</h3><p>Let’s dive into a basic example to see how simple it is to get started with React Query. The first thing you need to do is install the @tanstack/react-querylibrary. I will use npm for the execution.</p><pre>npm install @tanstack/react-query</pre><p>After the library is installed in our application, create a provider and client to use React Query. You can create it in the index.tsxfile in the srcfolder.</p><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom/client&#39;;<br>import &#39;./index.css&#39;;<br>import App from &#39;./App&#39;;<br>import { QueryClientProvider, QueryClient } from &#39;@tanstack/react-query&#39;;<br><br>const root = ReactDOM.createRoot(<br>  document.getElementById(&#39;root&#39;) as HTMLElement<br>);<br><br>const queryClient = new QueryClient();<br><br>root.render<br>  &lt;QueryClientProvider client={queryClient}&gt;<br>    &lt;App /&gt;<br>  &lt;/QueryClientProvider&gt;<br>);</pre><p>After that, you can immediately use React Query Hooks. Let’s apply it to the App.tsxscript.</p><pre>import React from &#39;react&#39;;<br>import logo from &#39;./logo.svg&#39;;<br>import &#39;./App.css&#39;;<br>import { useQuery } from &#39;@tanstack/react-query&#39;;<br><br>function App() {<br>  const userData = useQuery(<br>    [&#39;users&#39;], <br>    () =&gt; {<br>      return fetch(&#39;https://jsonplaceholder.typicode.com/users&#39;).then(response =&gt; response.json());<br>    },<br>    {<br>      enabled: false,<br>    }<br>  );<br><br>  return (<br>    &lt;div&gt;<br>      &lt;div&gt;<br>        &lt;button onClick={() =&gt; userData.refetch()}&gt;Get Users&lt;/button&gt;<br>        &lt;div&gt;<br>          {userData.isFetching &amp;&amp; (<br>            &lt;div&gt;Fetching user data...&lt;/div&gt;<br>          )}<br>          {userData.isError &amp;&amp; (<br>            &lt;div&gt;{`Error get data!!!`}&lt;/div&gt;<br>          )}<br>          {userData.data &amp;&amp; userData.data.length &gt; 0 &amp;&amp; userData.data.map((user: any) =&gt; (<br>            &lt;div&gt;{user.name}&lt;/div&gt;<br>          ))}<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>In this example, we use useQuery to fetch a list of users. React Query handles the fetching state, error handling, and caching behind the scenes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*VMVis07NyntygP6-WrYLRg.gif" /><figcaption>Get users with useQuery</figcaption></figure><p>When we click the Get Usersbutton, we are fetching data from the API. Because the amount of data is small, the fetching process becomes less visible because it is too fast.</p><p>Apart from useQuery, we also have useMutation where these hooks are almost the same as useQuery, but are used to mutate data. Below I show an example of its use. Just add this code.</p><pre>import React from &#39;react&#39;;<br>import logo from &#39;./logo.svg&#39;;<br>import &#39;./App.css&#39;;<br>import { useQuery, useMutation } from &#39;@tanstack/react-query&#39;;<br><br>function App() {<br>  const userData = useQuery(<br>    [&#39;users&#39;], <br>    () =&gt; {<br>      return fetch(&#39;https://jsonplaceholder.typicode.com/users&#39;).then(response =&gt; response.json());<br>    },<br>    {<br>      enabled: false,<br>    }<br>  );<br><br>  const mutatePost = useMutation(<br>    [&#39;posts&#39;],<br>    (newPost: any) =&gt; {<br>      return fetch(&#39;https://jsonplaceholder.typicode.com/posts&#39;, {<br>        method: &#39;POST&#39;,<br>        body: JSON.stringify(newPost),<br>        headers: {<br>          &#39;Content-type&#39;: &#39;application/json; charset=UTF-8&#39;,<br>        },<br>      }).then((response) =&gt; response.json())<br>    }<br>  )<br><br>  return (<br>    &lt;div&gt;<br>      &lt;div&gt;<br>        &lt;button onClick={() =&gt; userData.refetch()}&gt;Get Users&lt;/button&gt;<br>        &lt;div&gt;<br>          {userData.isFetching &amp;&amp; (<br>            &lt;div&gt;Fetching user data...&lt;/div&gt;<br>          )}<br>          {userData.isError &amp;&amp; (<br>            &lt;div&gt;{`Error get data!!!`}&lt;/div&gt;<br>          )}<br>          {userData.data &amp;&amp; userData.data.length &gt; 0 &amp;&amp; userData.data.map((user: any) =&gt; (<br>            &lt;div&gt;{user.name}&lt;/div&gt;<br>          ))}<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;hr /&gt;<br>      &lt;div&gt;<br>        &lt;button onClick={() =&gt; mutatePost.mutate({ title: &#39;First Post&#39;, body: &#39;First Post Body&#39;, userId: 1 })}&gt;Add New Post&lt;/button&gt;<br>        &lt;div&gt;<br>          {mutatePost.isLoading &amp;&amp; (<br>            &lt;div&gt;Adding new post...&lt;/div&gt;<br>          )}<br>          {mutatePost.isError &amp;&amp; (<br>            &lt;div&gt;{`Error add new post!!!`}&lt;/div&gt;<br>          )}<br>          {mutatePost.data &amp;&amp; (<br>            &lt;div&gt;{`Success add new post with title : &#39;${mutatePost.data.title}&#39;`}&lt;/div&gt;<br>          )}<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>In the example above we use useMutation to add a new post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*8PXYBNVu3ySVOCbBytoD4Q.gif" /><figcaption>Add new post with useMutation</figcaption></figure><h3>Difference between useQuery and useMutation</h3><ul><li><strong>Purpose:</strong> useQuery is for reading data, while useMutation is for modifying data.</li><li><strong>Typical Use Case:</strong> useQuery is used when you want to fetch and display data, while useMutation is used when you want to make changes to that data.</li><li><strong>Return Values:</strong> useQuery returns { data, error, isLoading, isFetching }, while useMutation returns { mutate, data, error, isError, isLoading, isSuccess }.</li><li><strong>Error Handling:</strong> Both hooks handle errors, but useMutation provides additional features for handling optimistic updates and rollbacks in case of errors during mutations.</li></ul><h3>Conclusion</h3><p>React Query is a valuable addition to the React ecosystem, making data fetching and synchronization easier than ever. Whether you’re building a small application or a large-scale project, React Query’s simplicity and powerful features will help you manage your data effectively.</p><p>By simplifying data management, React Query allows you to focus on building your application’s features and providing a better user experience. Give it a try in your next React project, and you’ll likely wonder how you managed data without it.</p><h3>Reference</h3><ul><li><a href="https://tanstack.com/query/latest/docs/react/overview">https://tanstack.com/query/latest/docs/react/overview</a></li><li><a href="https://github.com/TanStack/query">https://github.com/TanStack/query</a></li><li><a href="https://blog.logrocket.com/deep-dive-mutations-tanstack-query/">https://blog.logrocket.com/deep-dive-mutations-tanstack-query/</a></li><li><a href="https://thesyntaxdiaries.com/what-is-react-query-how-to-use-usemutation-usequery-prefetch-devtools/">https://thesyntaxdiaries.com/what-is-react-query-how-to-use-usemutation-usequery-prefetch-devtools/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11e56960e90c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/understanding-react-query-11e56960e90c">Understanding React Query</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Differences Between Redux Toolkit and Redux Saga]]></title>
            <link>https://medium.com/bina-nusantara-it-division/exploring-the-differences-between-redux-toolkit-and-redux-saga-5e46e9c97333?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e46e9c97333</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[redux-saga]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Tue, 27 Jun 2023 09:05:58 GMT</pubDate>
            <atom:updated>2023-06-27T09:05:58.552Z</atom:updated>
            <content:encoded><![CDATA[<h4>Comparing Two Essential Redux Libraries: Redux Toolkit and Redux Saga</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1ct4X9uberBLJXSZ.png" /><figcaption>Redux logo from redux.js.org</figcaption></figure><p>Redux is a popular state management library for JavaScript applications, widely used in conjunction with React. When working with Redux, developers often come across two prominent middleware solutions: Redux Toolkit and Redux Saga. Both serve different purposes and offer unique features that cater to specific needs in managing state and handling asynchronous actions.</p><p>In this article, we will delve into the key differences between Redux Toolkit and Redux Saga, their use cases, and when to choose one over the other.</p><h3>What is Redux Toolkit?</h3><p>Redux Toolkit is an official package provided by the Redux team to simplify and streamline the process of working with Redux in JavaScript applications. It aims to address common pain points and boilerplate code associated with setting up and managing a Redux store.</p><p>You can install Redux Toolkit with the following command :</p><pre>npm install @reduxjs/toolkit</pre><h4>Redux Toolkit features</h4><p>Redux Toolkit provides a set of utilities and abstractions that make it easier to write Redux code with fewer lines of code and improved developer experience. It includes several features and concepts that enhance productivity and enforces best practices:</p><ol><li><strong>configureStore</strong>: This function combines multiple Redux configurations, such as setting up the Redux store, applying middleware, and enabling Redux DevTools Extension, into a single function call. It simplifies the store setup process and eliminates the need to manually configure each aspect.</li><li><strong>createSlice</strong>: With createSlice, developers can define Redux slices, which encapsulate related reducers, actions, and selectors. It automatically generates the corresponding reducer functions and action creators based on the defined slice, reducing the boilerplate code traditionally associated with Redux.</li><li><strong>createAsyncThunk</strong>: This utility simplifies handling asynchronous operations, such as API requests, by generating thunk actions with standardized lifecycle states. It integrates with Redux Toolkit’s built-in loading, success, and error state management, making it easier to handle async logic in a predictable manner.</li><li><strong>createEntityAdapter</strong>: createEntityAdapter provides a standardized way to manage normalized data structures in the Redux store. It simplifies common CRUD (Create, Read, Update, Delete) operations and comes with built-in methods for manipulating entities.</li></ol><h4>Example</h4><p>Here’s an example of using the Redux Toolkit in a ReactJS application:</p><ul><li>Create a Redux Slice “counterSlice.ts”.</li></ul><pre>import { createSlice } from &quot;@reduxjs/toolkit&quot;;<br><br>const counterSlice = createSlice({<br>    name: &quot;counter&quot;,<br>    initialState: 0,<br>    reducers: {<br>        increment: (state) =&gt; state + 1,<br>        decrement: (state) =&gt; state - 1,<br>    },<br>});<br><br>export const { increment, decrement } = counterSlice.actions;<br><br>export default counterSlice.reducer;</pre><ul><li>Create the Redux Store “store.ts”.</li></ul><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import counterReducer from &#39;./counterSlice&#39;;<br><br>const store = configureStore({<br>  reducer: {<br>    counter: counterReducer,<br>  },<br>});<br><br>export default store;</pre><ul><li>Connect Redux Store to the React App.</li></ul><pre>import React from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { increment, decrement } from &#39;./counterSlice&#39;;<br><br>function App() {<br>  const counter = useSelector((state) =&gt; state.counter);<br>  const dispatch = useDispatch();<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Counter: {counter}&lt;/h1&gt;<br>      &lt;button onClick={() =&gt; dispatch(increment())}&gt;Increment&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch(decrement())}&gt;Decrement&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><ul><li>Wrap the App with Redux Provider.</li></ul><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom/client&#39;;<br>import &#39;./index.css&#39;;<br>import App from &#39;./App&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;./store&#39;;<br><br>const root = ReactDOM.createRoot(<br>  document.getElementById(&#39;root&#39;) as HTMLElement<br>);<br>root.render(<br>  &lt;Provider store={store}&gt;<br>    &lt;App /&gt;<br>  &lt;/Provider&gt;<br>);</pre><ul><li>Run the command “npm start” to start your application and see the result.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*Kj83xDeJ9zUMJoSlVgkqWQ.gif" /></figure><h3>What is Redux Saga?</h3><p>Redux Saga is a middleware library for Redux that allows you to handle side effects in your Redux application, such as asynchronous operations, network requests, and handling complex flows of actions. It follows the concept of generators and provides an alternative approach to managing side effects compared to traditional Redux Thunk.</p><h4>Redux Saga features</h4><p>Here are some key features and concepts of Redux Saga:</p><ol><li><strong>Side Effect Management</strong>: Redux Saga focuses on managing side effects, which are operations that occur asynchronously, such as API calls or interacting with browser APIs. It provides a structured way to handle these side effects by using generator functions.</li><li><strong>Generator Functions</strong>: Redux Saga leverages JavaScript generator functions (<strong>‘function*’</strong>) to write asynchronous code in a synchronous-looking manner. Generator functions allow you to pause and resume the execution of a function, which is useful for managing asynchronous flows.</li><li><strong>Sagas</strong>: Sagas are generator functions that encapsulate the logic for handling specific side effects. They listen for dispatched actions and perform corresponding tasks, such as making API calls or dispatching other actions.</li><li><strong>Effects</strong>: Redux Saga provides a set of predefined effect functions that represent different types of side effects. These effects include making API requests (<strong>call</strong>), delaying execution (<strong>delay</strong>), handling concurrency (<strong>fork</strong>, <strong>race</strong>), and more. Effects are used within sagas to define the behavior of specific side effects.</li><li><strong>Middleware Integration</strong>: Redux Saga is integrated into the Redux middleware pipeline. It intercepts dispatched actions before they reach the reducers, allowing you to handle side effects transparently in a separate layer.</li><li><strong>Testability</strong>: Redux Saga promotes testability by providing a declarative and deterministic way to write tests for your sagas. Since sagas are generator functions, you can test them by stepping through the yielded values and making assertions on the expected behavior.</li></ol><h4>Example</h4><p>Here’s an example of using Redux Saga in a ReactJS application:</p><ul><li>Create the Redux Action “actions.ts”.</li></ul><pre>export const GET_USER_FETCH = &#39;GET_USER_FETCH&#39;;<br>export const GET_USER_SUCCESS = &#39;GET_USER_SUCCESS&#39;;<br><br>export const getUserFetch = () =&gt; ({<br>    type: GET_USER_FETCH<br>}); </pre><ul><li>Create the Reducer “reducer.ts”.</li></ul><pre>import { GET_USER_SUCCESS } from &quot;./actions&quot;;<br><br>const initState = { user: [] };<br><br>const myReducer = (state = initState, action: any) =&gt; {<br>    switch(action.type) {<br>        case GET_USER_SUCCESS:<br>            return { ...state, user: action.user };<br>        default:<br>            return state;<br>    }<br>}<br><br>export default myReducer;</pre><ul><li>Create the Redux Saga “sagas.ts”. We use free fake API for testing from JSON Placeholder (Typicode).</li></ul><pre>import { call, put, takeEvery } from &#39;redux-saga/effects&#39;;<br>import { GET_USER_FETCH, GET_USER_SUCCESS } from &#39;./actions&#39;;<br><br>function userFetch() {<br>    return fetch(&#39;https://jsonplaceholder.typicode.com/users&#39;).then(response =&gt; response.json());<br>}<br><br>function* workerGetUserFetch() {<br>    const user: Promise&lt;any&gt; = yield call(userFetch);<br>    yield put({ type: GET_USER_SUCCESS, user });<br>}<br><br>function* mySaga() {<br>    yield takeEvery(GET_USER_FETCH, workerGetUserFetch);<br>}<br><br>export default mySaga;</pre><ul><li>Create the Redux Store “store.ts”.</li></ul><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import createSagaMiddleware from &#39;redux-saga&#39;;<br>import mySaga from &#39;./sagas&#39;;<br>import userReducer from &#39;./reducer&#39;;<br><br>const sagaMiddleware = createSagaMiddleware();<br><br>const store = configureStore({<br>  reducer: {<br>    user: userReducer<br>  },<br>  middleware: (getDefaultMiddleware) =&gt; getDefaultMiddleware().concat(sagaMiddleware),<br>});<br><br>sagaMiddleware.run(mySaga);<br><br>export default store;</pre><ul><li>Connect Redux Store to the React App.</li></ul><pre>import React from &#39;react&#39;;<br>import &#39;./App.css&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { increment, decrement } from &#39;./counterSlice&#39;;<br>import { getUserFetch } from &#39;./actions&#39;;<br><br>function App() {<br>  const user = useSelector((state: any) =&gt; state.user.user);<br>  const dispatch = useDispatch();<br><br>  return (<br>    &lt;div&gt;<br>      &lt;div&gt;<br>        &lt;button onClick={() =&gt; dispatch(getUserFetch())}&gt;Get Users&lt;/button&gt;<br>        &lt;div&gt;<br>          Users: {user.map((user: any) =&gt; (&lt;div&gt;{user.name}&lt;/div&gt;))}<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><ul><li>Wrap the App with Redux Provider just like we do before.</li><li>Finally start your application and see the result.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*0KaN2tfv2DBo5mMIFqqIXg.gif" /></figure><h3>Choosing the Right Solution</h3><ul><li><strong>Simplicity vs. Advanced Control</strong>: Redux Toolkit prioritizes simplicity, reducing the learning curve and providing a smoother developer experience. On the other hand, Redux Saga offers more flexibility and advanced features but requires a deeper understanding of generators and Redux middleware.</li><li><strong>Project Complexity</strong>: Consider the complexity of your project and the specific requirements for managing state and handling async actions. Redux Toolkit is suitable for simpler applications, while Redux Saga shines in more complex scenarios.</li><li><strong>Combination</strong>: Redux Toolkit and Redux Saga can be used together in the same application, leveraging the strengths of each solution for different parts of the state management and async action handling.</li></ul><h3>Conclusion</h3><p>Redux Toolkit and Redux Saga are two powerful libraries that serve different purposes in Redux-based applications. Redux Toolkit simplifies Redux development, reduces boilerplate, and provides an opinionated structure, making it suitable for smaller projects.</p><p>On the other hand, Redux Saga offers advanced control over asynchronous actions and complex side effects, making it ideal for larger applications with complex async workflows.</p><p>Choosing between Redux Toolkit and Redux Saga depends on your project’s requirements, complexity, and the level of control needed over state management and async action handling.</p><p>Remember, both libraries have their strengths, and it’s important to evaluate your specific project needs before deciding which one to use.</p><h3>Reference</h3><ul><li><a href="https://redux.js.org/redux-toolkit/overview">https://redux.js.org/redux-toolkit/overview</a></li><li><a href="https://symphony.is/blog/redux-toolkit-redux-with-less-code-part-i">https://symphony.is/blog/redux-toolkit-redux-with-less-code-part-i</a></li><li><a href="https://www.geeksforgeeks.org/what-is-redux-toolkit-and-why-it-is-more-preferred/">https://www.geeksforgeeks.org/what-is-redux-toolkit-and-why-it-is-more-preferred/</a></li><li><a href="https://redux-saga.js.org/docs/About">https://redux-saga.js.org/docs/About</a></li><li><a href="https://blog.logrocket.com/understanding-redux-saga-action-creators-sagas/">https://blog.logrocket.com/understanding-redux-saga-action-creators-sagas/</a></li><li><a href="https://www.makeuseof.com/react-redux-saga-how-fetch-data/">https://www.makeuseof.com/react-redux-saga-how-fetch-data/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e46e9c97333" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/exploring-the-differences-between-redux-toolkit-and-redux-saga-5e46e9c97333">Exploring the Differences Between Redux Toolkit and Redux Saga</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Progressive Web Apps with ReactJS]]></title>
            <link>https://medium.com/bina-nusantara-it-division/building-progressive-web-apps-with-reactjs-5a5433c07873?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a5433c07873</guid>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[progressive-web-app]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 00:33:22 GMT</pubDate>
            <atom:updated>2023-03-29T00:33:22.196Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to create fast and engaging web applications with ReactJS and PWA technologies</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxantp2NzJRbtFqISxLaEg.jpeg" /><figcaption>unsplash.com</figcaption></figure><p>Progressive Web Apps (PWA) are becoming increasingly popular among developers and users alike. They offer a combination of the best features of both mobile and web apps, providing a fast, reliable, and engaging experience to users while being easy to develop and maintain for developers. In this article, we’ll explore how to create a PWA using ReactJS, one of the most popular JavaScript libraries for building user interfaces.</p><h3>What is a PWA?</h3><p>A PWA is a web app that uses modern web technologies to provide users with an app-like experience. PWAs are designed to work across all devices and platforms, whether it’s a desktop computer, a tablet, or a mobile phone. PWAs can be installed on a user’s device and work offline, just like a native app. PWAs can also access native features like the camera and push notifications.</p><h3>Why use PWA?</h3><p>PWAs offer several benefits over traditional web apps, including:</p><ol><li>Fast and reliable performance: PWAs are designed to be fast and responsive, even on slow or unreliable network connections. They can also work offline, allowing users to continue using the app even when they don’t have an internet connection.</li><li>App-like user experience: PWAs offer an app-like user interface and can be added to a user’s home screen. They can also access native device features, such as push notifications and camera access.</li><li>Easy to develop and maintain: PWAs are built using web technologies, such as HTML, CSS, and JavaScript, which means that developers can leverage their existing skills to create PWAs. PWAs are also easy to maintain, as updates can be deployed to all users instantly.</li><li>More secure: PWAs are also more secure than traditional web applications because they use HTTPS, which encrypts all data that is sent between the app and the server. This makes it much harder for hackers to intercept and steal user data.</li></ol><h3>Why ReactJS for PWA?</h3><p>ReactJS is a popular frontend library for building web apps. ReactJS uses a virtual DOM, making it fast and efficient, which is important for a PWA. ReactJS also allows for the creation of reusable components, making it easier to maintain a PWA.</p><h3>Getting Started with ReactJS PWA</h3><p>To create a PWA using ReactJS, we need to start with a React app. We can use the create-react-app CLI tool to create a new React app. In the terminal, run the following command:</p><pre>npx create-react-app my-pwa-app --template cra-template-pwa</pre><p>This will create a new React app with PWA features already added. We can test if the PWA features are working by running the app and opening it in a web browser. We should see a prompt to install the app on our device.</p><h3>Adding PWA Features</h3><p>Now that we have a basic PWA app, we can add more PWA features to improve the user experience. Here are some PWA features we can add to our ReactJS app:</p><ol><li>Service Workers — Service workers are scripts that run in the background and handle network requests. We can use a service worker to cache our app’s assets, making the app load faster even when the user is offline.</li><li>Manifest File — A manifest file is a JSON file that provides information about the app, such as its name and icon. We can use a manifest file to make our app installable on a user’s device.</li><li>Push Notifications — Push notifications are a great way to keep users engaged with our app. We can use a service worker to handle push notifications and display them to the user.</li></ol><h3>Conclusion</h3><p>PWAs are a great way to build web applications that provide a native-like experience to the user. PWAs are built using web technologies, such as HTML, CSS, and Javascript, and can run on any device that has a web browser.</p><p>ReactJS is a popular javascript library for building user interfaces. ReactJS can be used to build PWAs by using the ReactJS framework and a few additional libraries, such as the service worker library and the React Router library.</p><p>If you are interested in building PWA with ReactJS, there are many resources available online that can help you get started. By building a PWA with ReactJS, you can provide your users with a great user experience that works offline, provides push notifications, and is more secure than traditional web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a5433c07873" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/building-progressive-web-apps-with-reactjs-5a5433c07873">Building Progressive Web Apps with ReactJS</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</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 Deploy your Next.js Apps on Linux server using Nginx and PM2]]></title>
            <link>https://medium.com/bina-nusantara-it-division/how-to-deploy-your-next-js-apps-on-linux-server-using-nginx-and-pm2-65834cfecd37?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/65834cfecd37</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[pm2]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 02:10:29 GMT</pubDate>
            <atom:updated>2022-09-28T02:10:29.877Z</atom:updated>
            <content:encoded><![CDATA[<h4>Tutorial on how to deploy your Next.js application to a Linux server using Nginx and PM2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RdsetF14kxuCnQWb.jpg" /></figure><p>Nowadays, many people use web or mobile applications for their daily activities. This makes the demand for web and mobile application development very high. There are many frameworks for web development, one of the most famous is Next.js. Then how do we deploy a web application using the Next.js framework? In this tutorial we will discuss how to deploy our Next.js web application on a Linux server.</p><h4>Create your first project</h4><p>The first step we need to do is create a new project. Make sure you have node with the latest version. If you are not sure you can use the following command to check the version of node on your system.</p><pre>node -v</pre><p>If the command provides information on your node version then you already have node on your system, otherwise you will have to install node first.</p><p>Once you’ve confirmed that you have nodes on your system, you can immediately create a new project using the following command.</p><pre>npx create-next-app@latest</pre><p>the above command will generate a new and fresh next.js project. You will be asked to enter the name of the application you created. Enter the name of the application as you like and keep in mind that the name of the application cannot use uppercase letters. After the process of creating a new project is complete, the arrangement of the project folders and files will look like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*kIG1q5mQMd3xrdnCgIr1sA.png" /></figure><h4>Install Dependencies</h4><p>The next step is that we have to install the dependencies used in our project. After we install our dependencies there will be a folder named “node_modules” in our project. But usually when we create a new project, all the basic dependencies will be installed immediately. For the command we use is as follows.</p><pre>npm install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*3CY2kJ2k88RxZVW3-chfmw.png" /></figure><p>Until now we should be able to run our Next application in development mode. The command used is as follows.</p><pre>npm run dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*Qqh6mm11-B5tZDYC06yfzA.png" /></figure><p>By default, our application can be accessed via localhost with port number 3000. But the deployment process is not finished yet because we need to deploy our application in production mode.</p><h4>Build and Start our App in Production Mode</h4><p>To start our app in production mode, we need to build the project first. Use the following command to build the project.</p><pre>npm run build</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*Oh7FgIbuID9c55BmFWuVgw.png" /></figure><p>After the project build process has been completed successfully, the next step is to run the following command to start our application in production mode.</p><pre>npm run start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*Ik72Y3uW4zgytKCH28WWdA.png" /></figure><p>Congratulations, your Next application has been successfully deployed in production mode and can be accessed via localhost with port number 3000. Has our deployment process finished here? NOT YET. We still have to set our application to run in the background and also set up a reverse proxy so that our application can be accessed using the domain name we want.</p><h4>Setting PM2</h4><p>So to run our Next application in the background, we need to use PM2. First of all we have to install PM2 on our system. Use the following command to install PM2.</p><pre>npm install -g pm2</pre><p>After PM2 is installed on our system, we can run our Next application in the background using PM2 with the following command.</p><pre>pm2 start &quot;npm run start&quot; --name &quot;[YourAppName]&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FgJjBu__NTkMeOkY1Bjjqw.png" /></figure><p>Okay now your application is running in the background. Next we will set Nginx to reverse proxy with the application that we have deployed.</p><h4>Setting NGINX</h4><p>I assume you have Nginx installed on your system. The final step is that we need to configure our Nginx configuration file. Usually the file is in the directory with the address “/etc/nginx/conf.d”. Here we will create a new configuration file for our application. Let’s create a new file using the Nano text editor. Run the following command.</p><pre>sudo nano [domainName].conf</pre><p>Enter the following script as the configuration of our Nginx in the editor.</p><pre>server {<br>        listen       80;<br>        listen       [::]:80;<br>        server_name  testnextdeploy.com www.testnextdeploy.com;</pre><pre>location / {<br>                # reverse proxy for next server<br>                proxy_pass http://localhost:3000;<br>                proxy_http_version 1.1;<br>                proxy_set_header Upgrade $http_upgrade;<br>                proxy_set_header Connection &#39;upgrade&#39;;<br>                proxy_set_header Host $host;<br>                proxy_cache_bypass $http_upgrade;<br>        }<br>}</pre><p>After that save your script and restart Nginx with the following command.</p><pre>sudo nginx -t<br>sudo systemctl restart nginx</pre><p>Your application should be accessible via a browser as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pwt1ahPqAeDuVFLOQnN52w.png" /></figure><h4>Conclusion</h4><p>The deployment process is not too difficult because we are helped by the presence of PM2 and Nginx, where PM2 functions as an application that can run a service in the background and Nginx functions as a reverse proxy so that our application can be recognized and accessed from outside. However, please note that the Nginx configuration above is a configuration for the http service where it is not so safe, but you can configure the https service so that your application is more secure. Thank you for reading this article, I hope this article is useful and Happy Deploying…!!! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65834cfecd37" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/how-to-deploy-your-next-js-apps-on-linux-server-using-nginx-and-pm2-65834cfecd37">How to Deploy your Next.js Apps on Linux server using Nginx and PM2</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</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 Install and Configure your first Laravel Application]]></title>
            <link>https://medium.com/bina-nusantara-it-division/how-to-install-and-configure-your-first-laravel-application-3f247924de59?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f247924de59</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[xampp]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[composer]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Thu, 30 Jun 2022 07:54:26 GMT</pubDate>
            <atom:updated>2022-06-30T07:54:26.726Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this lesson, you will learn how to create your first Laravel project.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2E_W-RIKB3bT6_NF.png" /></figure><p>Currently Laravel is quite popular among web application development circles. Laravel has been widely used in various types of needs such as dashboards, e-commerce, blogs, job sites, and others. So, let’s get started with creating our first Laravel project.</p><h3>What is Laravel?</h3><p>Laravel is an open-source PHP framework, which is robust and easy to understand. It follows a model-view-controller design pattern. Laravel reuses the existing components of different frameworks which helps in creating a web application. The web application thus designed is more structured and pragmatic.</p><p>If you are familiar with Core PHP and Advanced PHP, Laravel will make your task easier. It saves a lot time if you are planning to develop a website from scratch. Moreover, a website built in Laravel is secure and prevents several web attacks.</p><h3>Getting Started</h3><p>Before you can create a new Laravel project, you need to first check and make sure that you have PHP and Composer installed on your system.</p><p>Check your PHP and Composer version by running this command in your Command Prompt/Terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*QhMaFdwZjqjqM96TIOjmtw.png" /></figure><p>If you can’t find your version of PHP and Composer then you need to install it first.</p><h3>Install PHP</h3><p>To install PHP you can get it from XAMPP, therefore you need to install XAMPP first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSTUceTjsuZ4QN9n9V4NtA.png" /><figcaption><a href="https://www.apachefriends.org/download.html">https://www.apachefriends.org/download.html</a></figcaption></figure><p>You can choose the XAMPP installer with a minimum PHP version of 7.4.29.</p><p>After you download the installer, you can directly install it and follow the instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*mRe4X3bIJVKtsOmLBZ-fWw.png" /><figcaption>XAMPP Control Panel</figcaption></figure><p>After XAMPP is installed on your system, PHP will also be installed on your system.</p><h3>Install Composer</h3><p>To install Composer on your system, you need to first download the installer on the official website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Om5hXgCGAYjP1pnPtfPoQ.png" /><figcaption><a href="https://getcomposer.org/download/">https://getcomposer.org/download/</a></figcaption></figure><p>After you download the installer, you can directly install it and follow the instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*TVz8bS8lYusCnV6eRLXw5Q.png" /></figure><p>The PHP command-line will be filled in automatically if you have previously installed PHP using XAMPP. So you can leave it filled by default.</p><h3>Your First Laravel Project</h3><p>After you have installed PHP and Composer, you may create a new Laravel project via the Composer command:</p><pre>composer create-project laravel/laravel your-app-name</pre><p>The process will take a long time because in this process Composer will download all the package files needed for your Laravel project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qGRFkTy7ko8geGEuq1u4A.png" /></figure><p>After the download is complete, you can immediately run your first laravel project using the Artisan command. Before that you first go into your Laravel project folder, in my case it is “benny-laravel-app”.</p><pre>cd benny-laravel-app</pre><p>Once you are in your project folder, you can immediately run the following Artisan command:</p><pre>php artisan serve</pre><p>And congratulations!!! Your first Laravel project is running successfully. Now you can enter the url address to open your Laravel website in your browser. By default it is usually <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P977GfbaedY--g6CUJEm4w.png" /></figure><h3>Conclusion</h3><p>The method above is how to create a Laravel project using Composer. There is actually another way to build your Laravel project from scratch. However, I personally use Composer more often to create new Laravel projects because it’s easier in my opinion. So it’s very easy if we want to create a website using Laravel.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f247924de59" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/how-to-install-and-configure-your-first-laravel-application-3f247924de59">How to Install and Configure your first Laravel Application</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</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 deploy your ASP.Net Core Web API on Heroku using Docker]]></title>
            <link>https://medium.com/bina-nusantara-it-division/how-to-deploy-your-asp-net-core-web-api-on-heroku-using-docker-a21409881d76?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/a21409881d76</guid>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[games]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 09:42:57 GMT</pubDate>
            <atom:updated>2022-03-30T09:42:57.863Z</atom:updated>
            <content:encoded><![CDATA[<h4>Deploy your ASP.Net Core Web API on Heroku for free using Docker</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSmzhhQpMQC1MuyAiZm-xw.png" /></figure><p>As a developer, sometimes we like to create applications such as games, web applications, and others that require data from a web API and we want to show it to our colleagues or friends. The problem is we have to publish the web API so that it can be used in general. We don’t have servers to deploy web APIs and we don’t have enough money to use Azure or AWS. And the solution is that we can use Heroku to deploy our Web API using Docker as a container.</p><h3>What is Heroku?</h3><p>Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.</p><p>Currently, Heroku supports languages Ruby, Java, PHP, Python, Node, Go, Scala and Clojure but unfortunately not .Net or .Net Core. That’s why we need Docker in order to deploy our .Net core Web API. Heroku has a feature that allows us to deploy our applications using Docker.</p><h3>Getting Started</h3><h4>Install Docker</h4><p>The first thing we need to do is install Docker. You can download and install Docker from the official website <a href="https://www.docker.com/">https://www.docker.com/</a>.</p><h4>Create new ASP.Net Core Web API</h4><p>After we install Docker, we will create an ASP.Net Core 3.1 Web API application. Let’s open our Visual Studio and create a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_tZRWDdx8iiD-Ik2AiPcQ.png" /></figure><p>After that we enter the name of the project according to our wishes and the location of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M4v7IgmGOy9lZYmy3udUDg.png" /></figure><p>Next, we define the Target framework that we will use and for now we will choose .NET Core 3.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-mJPe-k0USsScok5qH-I5A.png" /></figure><p>Finally, your project should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*CpT49I7OY9KlX3v9A8bWxw.png" /></figure><p>The default template comes with a WeatherForecastController it has nothing special just a plain controller with some endpoints. You can modify it you if like.</p><p>Next, we need to create a Dockerfile to run some commands. The script should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68fc597f1b6d76920e768a2d68604d9b/href">https://medium.com/media/68fc597f1b6d76920e768a2d68604d9b/href</a></iframe><p>And now, Using the terminal, change the directory to the location where Dockerfile resides and run this command.</p><pre>-- Build docker image<br>docker build -t benny_api_image .</pre><pre>-- Run docker image and create new container<br>docker run -d -p 5000:80 --name benny_api_container benny_api_image</pre><p>Hit <a href="http://localhost:5000/weatherforecast">http://localhost:5000/weatherforecast</a> in your browser and you’ll see the return from the API.</p><h4>Getting ready for the Heroku</h4><p>We need to modify our script “Program.cs” before publishing it to the cloud.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f7d8d051e013c21023a2da4c2cb0031/href">https://medium.com/media/3f7d8d051e013c21023a2da4c2cb0031/href</a></iframe><p>After that, We need to install Heroku-CLI that will help us to deploy images to Heroku. Let’s create a new app on Heroku.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFqPvdXlxskq3XhemRgffQ.png" /></figure><p>Input the name for your new app. The name should be lowercase, number, and dash. If you browse to your app (<a href="https://benny-api.herokuapp.com/">https://benny-api.herokuapp.com/</a>). You will see a welcome screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P7MYwOeiaxjLbfvcuAn7Pw.png" /></figure><p>Now it’s time for us to deploy our API to Heroku. We need to login first to Heroku via CLI. Open your terminal and move to the directory where your Dockerfile is located. After that enter the command below.</p><pre>heroku login</pre><p>It will open the login page in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*OsKWFv3Ungz-0ch2.png" /></figure><p>After you have successfully logged in, run the following commands.</p><pre>-- Login to Heroku account<br>heroku login</pre><pre>-- Login to Heroku container<br>heroku container:login</pre><pre>-- Login to heroku docker<br>docker login --username=_ --password=$(heroku auth:token) registry.heroku.com</pre><pre>-- Build heroku docker image<br>docker build -t registry.heroku.com/benny-api/web .</pre><pre>-- Push heroku docker image<br>docker push registry.heroku.com/benny-api/web</pre><pre>-- Release the image on heroku<br>heroku container:release web --app benny-api</pre><p>“benny-api” is the app name, you can replace it with your app name.</p><p>Now, if you hit the URL “<a href="https://benny-api.herokuapp.com/weatherforecast">https://benny-api.herokuapp.com/weatherforecast</a>” it’ll return some data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l9a0wVitxIeVIUe1vCJvSQ.png" /></figure><p>Congratulations, you have successfully deployed your Web API and access it from anywhere.</p><h3>Conclusion</h3><p>To deploy your Web API is not so difficult and expensive, using Heroku and Docker you can deploy easily and for free. And now you can share your application with everyone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a21409881d76" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/how-to-deploy-your-asp-net-core-web-api-on-heroku-using-docker-a21409881d76">How to deploy your ASP.Net Core Web API on Heroku using Docker</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use LINQ in UNITY Games]]></title>
            <link>https://medium.com/bina-nusantara-it-division/use-linq-in-unity-games-30e144a70036?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/30e144a70036</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[linq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 08:00:05 GMT</pubDate>
            <atom:updated>2021-12-27T08:00:05.274Z</atom:updated>
            <content:encoded><![CDATA[<h4>LINQ makes it easier for game developers to develop games</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*5A_cfRF___6Qe5P7" /><figcaption>Image from ShutterStock</figcaption></figure><p>Are you developing a game that uses a lot of data? When you develop a game that has a lot of data, you must have difficulty managing that data. There may be many ways and algorithms that can be used, but it will take up a lot of your time.</p><p>Let’s speed up our game development process to manage that troublesome data using LINQ.</p><h3>What is LINQ?</h3><p>LINQ (Language Integrated Query) is uniform query syntax in C# to retrieve data from different sources and formats. It is integrated in C#, thereby eliminating the mismatch between programming languages and databases, as well as providing a single querying interface for different types of data sources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/0*a5hJcM8uCeRh13tr.PNG" /><figcaption>Image from www.tutorialsteacher.com</figcaption></figure><h3>Getting Started</h3><p>To be able to use LINQ in your C# script, it’s very simple. You just need to add a namespace like this.</p><pre>using System.Linq;</pre><h3>How to use LINQ in your code</h3><p>LINQ can be used in 2 ways, including Method syntax and Query syntax. Here’s how to use the two syntaxes, as an example we want to get an item of type “Weapon”.</p><p><strong>Method syntax</strong></p><pre>var item = listItem.Where(x =&gt; x.itemType.Equals(&quot;Weapon&quot;));</pre><p><strong>Query syntax</strong></p><pre>var item = from x in listItem<br>           where x.itemType.Equals(&quot;Weapon&quot;)<br>           select x;</pre><h3>Let’s see how it works in Unity</h3><p>Let’s create a store system where there will be a feature to search for items by type. The first step, of course, is to create a new scene. After that, make the UI look like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*pJZcLfvaQDnLONSgm5AZpw.png" /><figcaption>Simple Shop UI</figcaption></figure><p>And don’t forget to create a GameObject which we will use as a place to display our list of items. The GameObject that we will use is a UI Button and we design it as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*IlMeuxlfbQe2rSJU9uGgbg.png" /><figcaption>Item Button Object</figcaption></figure><p>Now we will need to create a script to help us attach our item property to the Button. The script can be made like this.</p><p><strong>ItemButton.cs</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74b7a222d88f460c1e2ea187d9880701/href">https://medium.com/media/74b7a222d88f460c1e2ea187d9880701/href</a></iframe><p>Usually I use Query syntax more often than Method syntax. The reason I use it is because the Query syntax is more similar to SQL Query in general hence increases code readability. So, let’s create a main script that will be used to process item search using LINQ.</p><p><strong>TutorialLINQ.cs</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/377b42e0ace50a5a277e6a5eed659dd3/href">https://medium.com/media/377b42e0ace50a5a277e6a5eed659dd3/href</a></iframe><p>As you can see, I am using the Query syntax in my LINQ usage. Maybe someone is confused with the word “data” in the Query syntax script snippet. Don’t worry, it’s just a variable name for a data which in this case is item data. You can use any name other than “data” like “item”, “x”, “someItem”, or whatever you like.</p><p>Then, how to apply it if you use Method syntax? It can be done using code like this.</p><pre>var theData = listItem.Where(data =&gt; data.itemType.Equals(itemTypeList.captionText.text)).ToList();</pre><p>Okay now let’s try to run the game and see the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*AOmRSrOAWHOGuUb7KjvjDA.gif" /><figcaption>GIF by Author</figcaption></figure><h3>Conclusion</h3><p>LINQ is a very useful feature for game developers. LINQ can be used in many ways such as searching, filtering, sorting, and much more, and all that can be done easily without having to think about complex algorithms. Outside of game development, LINQ is also widely used in the development of other applications that use the C# language.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30e144a70036" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/use-linq-in-unity-games-30e144a70036">Use LINQ in UNITY Games</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</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 fetch data from API in Unity]]></title>
            <link>https://medium.com/bina-nusantara-it-division/how-to-fetch-data-from-api-in-unity-99e58820b2d4?source=rss-23d36d481dee------2</link>
            <guid isPermaLink="false">https://medium.com/p/99e58820b2d4</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Benny]]></dc:creator>
            <pubDate>Thu, 23 Dec 2021 04:30:11 GMT</pubDate>
            <atom:updated>2021-12-23T04:30:11.875Z</atom:updated>
            <content:encoded><![CDATA[<h4>Tutorial on how to fetch data from API for your game in Unity</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*y2V_EvJ1ddp4chbr59958Q.png" /><figcaption>Unity Logo from <a href="http://www.unity.com/">www.unity.com</a></figcaption></figure><p>Have you ever thought of getting data for your game from the internet? Let’s say you have an online game and save the data to the internet and get it back to your game. So you don’t have to save the data to local memory and make your game heavier.<br>Well, you can easily get data from the internet by using REST API.</p><h3><strong>What is REST API?</strong></h3><p>REST (Representational state transfer) and API (Application Programming Interface) is a web service that provides a place for interaction between client and server. This interaction produces a JavaScript object notation or also known as JSON which can be used by many software.</p><p>With Unity, using REST API can be really helpful. Not only it will make your games lighter but it can also make it easier for developers to add updated data to their games.</p><p>For example, you published a game without a REST API and you want to update enemies status because it’s too strong for the player to defeat the monsters. So you have to manually update your game, rebuild it, and upload it again to the public. it’s really troublesome right?</p><p>If you use REST API, all you need to do is to go to your server, update that specific data, save it, and see the magic works.</p><h3><strong>Getting Started</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*Ma38AlcAz4N4Gl1nl19xZg.png" /><figcaption>MockAPI new project</figcaption></figure><p>For this tutorial, we’re gonna be using MockAPI to get character status and display them in our game. However, if you have other APIs that you want to use feel free to use it since the process of getting data with REST API is pretty much the same. Just make sure you have the API keys and other keys provided by the API of your choice.</p><p>First, you need to create the schema data for your API. We add character status like HP (Healt Point), MP (Magic Point), Attack, Defense, and Agility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*hb6uc609wbUio6og5hjI0g.png" /><figcaption>API Schema for Player Status</figcaption></figure><h3><strong>Create new project in Unity</strong></h3><p>Let’s create our new project in Unity. On the Projects menu Click “New” button on Unity hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*m_70fJhiuN5n5rwM7VN4gg.png" /><figcaption>Unity Hub Screen</figcaption></figure><p>At this point, you can choose template for your games. For now we can use 3D templates. After that you can set your project name and select location of your projects to be saved and click “Create”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*Uh7C1YapzpW89u1m8hxj8g.png" /><figcaption>Create new project</figcaption></figure><p>Wait for unity to prepare your new projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sGfRDvbhrckbFe55t3oOcg.png" /><figcaption>New Unity Project</figcaption></figure><h3><strong>Create New Script</strong></h3><p>Now our project is ready and we can create new script for our game. Right click on project window, select “Create” and then select “C# Script”. In this case, I’ll create new folder and name it “Script” and put the new script in there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*3JazDJbCOzN_BzI9uXUrcw.png" /><figcaption>Create New Script</figcaption></figure><p>First, we create script <em>PlayerStatus.cs</em> for our Model data that will receive data from API. After that, you can open and edit the script with Visual Studio and use the following code :</p><pre>using System.Collections;</pre><pre>using System.Collections.Generic;</pre><pre>using UnityEngine;</pre><pre>public class PlayerStatus</pre><pre>{</pre><pre>public string playerName;</pre><pre>public int atk;</pre><pre>public int def;</pre><pre>public int agi;</pre><pre>public int hp;</pre><pre>public int mp;</pre><pre>public string id;</pre><pre>}</pre><p>After that, we create next script <em>GetApiData.cs</em> for get and process the data from API. Use the following code below :</p><pre>using System.Collections;</pre><pre>using System.Collections.Generic;</pre><pre>using UnityEngine;</pre><pre>using UnityEngine.Networking;</pre><pre>using UnityEngine.UI;</pre><pre>public class GetApiData : MonoBehaviour</pre><pre>{</pre><pre>public string URL;</pre><pre>public InputField id;</pre><pre>public GameObject playerStatusPanel;<br></pre><pre>public void GetData()</pre><pre>{</pre><pre>StartCoroutine(FetchData());</pre><pre>}</pre><pre>public IEnumerator FetchData()</pre><pre>{</pre><pre>using (UnityWebRequest request = UnityWebRequest.Get(URL + id.text))</pre><pre>{</pre><pre>yield return request.SendWebRequest();</pre><pre>if (request.result == UnityWebRequest.Result.ConnectionError)</pre><pre>{</pre><pre>Debug.Log(request.error);</pre><pre>}</pre><pre>else</pre><pre>{</pre><pre>PlayerStatus playerStat = new PlayerStatus();</pre><pre>playerStat = JsonUtility.FromJson&lt;PlayerStatus&gt;(request.downloadHandler.text);</pre><pre>playerStatusPanel.transform.GetChild(0).GetComponent&lt;Text&gt;().text = playerStat.playerName;</pre><pre>playerStatusPanel.transform.GetChild(1).GetComponent&lt;Text&gt;().text = &quot;HP : &quot; + playerStat.hp.ToString();</pre><pre>playerStatusPanel.transform.GetChild(2).GetComponent&lt;Text&gt;().text = &quot;MP : &quot; + playerStat.mp.ToString();</pre><pre>playerStatusPanel.transform.GetChild(3).GetComponent&lt;Text&gt;().text = &quot;Attack : &quot; + playerStat.atk.ToString();</pre><pre>playerStatusPanel.transform.GetChild(4).GetComponent&lt;Text&gt;().text = &quot;Defende : &quot; + playerStat.def.ToString();</pre><pre>playerStatusPanel.transform.GetChild(5).GetComponent&lt;Text&gt;().text = &quot;Agility : &quot; + playerStat.agi.ToString();</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>}</pre><p>I’ll explain the code above step by step. First we create 3 variables :</p><ul><li>public string URL =&gt; A Variable that we use for our API endpoint link.</li><li>public InputField id =&gt; A Variable that we use for ID to get the data. This variable will receive input from user.</li><li>public GameObject playerStatusPanel =&gt; A Variable that we use for control Game Object in the game.</li></ul><p>After that, we create 2 functions “public void GetData()” and “public IEnumerator FetchData()”. The GetData() function is going to be used by our UI Button. So whenever you click the button, this funcion will be called. Inside this function, we started a coroutine for our IEnumerator function. Since we can’t just call the IEnumerator function from button click, we had to create GetData() function just to fire the IEnumerator function.</p><p>Inside the FetchData() function, we initialized the “UnityWebRequest” and then we send the URL of our API Endpoint for processing the data. Then, we wait for its response and after getting the response we check if it’s a failure or a success. If there is an error we display the error in our console and if it’s a success we create new variable for our Model data that we made earlier, and pass the data from JSON into that model. After that, we can display the data into our Game Object.</p><h3>Design the game UI</h3><p>Next thing to do is design our game UI. Let’s make it a simple UI for our game. On the Hierarchy window, right click on some object or click “+” button, select “Game Object”, select “UI”, select “Text”. We will create some text UI, a button, and an input field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*tTOQmZNJVMKQ4J8vDjrc4Q.png" /><figcaption>Create an UI Panel</figcaption></figure><p>After we create everything we need, the list of objects on hierarchy window will be like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*yaxQ3NaL65lYTI0Wdgm3Eg.png" /><figcaption>Hierarchy window</figcaption></figure><p>And the game UI will be like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*Kce7gReMm7FQKsGJ1ZRodQ.png" /><figcaption>UI design</figcaption></figure><h3>Setting up our game</h3><p>Now, our porject is almost done. You have to applied your script to your game. First thing to do is create empty Game Object as a place for our script, we will name it “GameManager”. And we just drag the script <em>GetApiData.cs</em> into that Game Object. After that, the new Game Object we create earlier will have a component of our script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*Qbt3pW6KfC0yW13duQMAyQ.png" /><figcaption>Inspector of GameManager Object</figcaption></figure><p>After that, we want our button to call the GetData() function we create earlier. So, on the button object, we look for “On Click ()” attribute and we click the “+” button. After that we drag the GameManager object from hierarchy into “On Click ()” attribute. Then, we can choose the function that we want to call in this case GetData() function. It will looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*eOFrjuVuIPA9e67bauu5LQ.png" /><figcaption>On Click () Attribute for Button</figcaption></figure><h3>Run your game</h3><p>We done!! You can run your game by click the play button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*8-j4zaURjSbu8G-Sk7e7Wg.png" /><figcaption>Get Data From API</figcaption></figure><h3>Conclusion</h3><p>RESTful API is the best features that make us easier to transfer data between client and server. It can be used by any programming language and any platform. With REST API, you can do more things other than displaying players status. You can send notification to player, chatting system, update item list on NPC shop, and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99e58820b2d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bina-nusantara-it-division/how-to-fetch-data-from-api-in-unity-99e58820b2d4">How to fetch data from API in Unity</a> was originally published in <a href="https://medium.com/bina-nusantara-it-division">Bina Nusantara IT Division</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>