Author: Shekhar Sharma

  • Flutter vs. React Native: What You Need to Know Before Choosing Your Mobile App Framework

    Flutter vs. React Native: What You Need to Know Before Choosing Your Mobile App Framework

    Flutter and React Native are two of the most popular cross-platform mobile app development frameworks available today. Both frameworks allow developers to build high-quality apps for iOS and Android using a single codebase, saving time and effort compared to building separate apps for each platform.

    In this comparison, we will look at the critical differences between Flutter and React Native, including programming language, user interface, performance, community, and development time. Understanding these differences can help developers make informed decisions when choosing a framework for their next mobile app project.

    React Native vs Flutter

    1. Programming Language: React Native uses JavaScript, while Flutter uses Dart.
    2. User Interface: React Native uses native components to provide a traditional look and feel. At the same time, Flutter has its own unique widgets and designs.
    3. Performance: React Native can perform better with native modules, but Flutter has a faster development cycle and a hot reload feature.
    4. Community: React Native has a larger community and a more extended history, while Flutter has a growing community and faster-growing popularity.
    5. Development Time: React Native has a mature ecosystem and an extensive library of modules, which can make development faster for specific apps. At the same time, Flutter is known for more rapid app development due to its hot reload feature.
    6. Debugging: React Native provides better debugging options, while Flutter has a more efficient reload feature.
    7. Testing: Both React Native and Flutter have strong testing capabilities, but React Native has a larger pool of testing tools available.
    8. Documentation and Support: React Native has more comprehensive documentation and support. In contrast, Flutter has growing documentation and support from its growing community.
    9. App Size: Flutter tends to have larger app sizes than React Native.
    10. Community Contributions: React Native has a larger pool of third-party libraries and packages. In contrast, Flutter has a growing collection of contributions from its growing community.

    What are Flutter’s Advantages

    Flutter has many advantages, making it a good choice for mobile app development. It allows for faster app development with its “hot reload” feature, which shows real-time changes. It also has unique designs and widgets, making the app look different from others. The framework runs quickly and smoothly, providing a good experience for users. It’s easy to learn, open-source, and can be used for multiple types of app development, including web and desktop. Additionally, it has an extensive collection of pre-designed widgets to help create beautiful and functional apps.

    Why choose React Native over Flutter?

    React Native is a well-established framework for developing mobile apps and has several advantages over other frameworks, including Flutter. Here are some reasons why one might choose React Native over Flutter:

    First, React Native has a larger and more mature community of developers. This can provide a wealth of support and resources, including third-party modules and libraries that can be used in the app. This larger community can also offer a pool of developers to draw from when looking to hire or bring new talent on board.

    Second, React Native uses JavaScript, a widely-used programming language that many developers are already familiar with. This can make it easier to find developers with the right skills and reduce the time and cost required to train new hires.

    Third, React Native uses native components, the building blocks of native apps, to create a traditional look and feel. This can help to create a more familiar and intuitive experience for users. Additionally, using native components can also lead to better performance compared to using custom widgets.

    Fourth, React Native provides better debugging options, making it easier for developers to find and fix bugs. This can save time and effort and can result in a higher-quality app.

    Finally, React Native has a broader range of testing tools available, making testing the app easier and ensuring its quality. This can help catch bugs early in the development process and prevent the app from crashing or behaving unexpectedly for users.

    So which framework is better?

    Neither React Native nor Flutter is objectively “better,” as the choice of framework depends on the specific requirements and goals of the project. Both frameworks have unique strengths and weaknesses, and the best option depends on the particular needs of the project, the team’s expertise, and other factors.

    For example, if a developer is familiar with JavaScript and wants to use a framework with a larger community, React Native may be a better choice. On the other hand, if a developer wants to create a highly customized and visually stunning app, Flutter may be the better option due to its extensive widget library and ability to create beautiful, fast animations.

    Ultimately, the best framework choice will depend on the specific requirements and goals of the project. Therefore, it’s essential to carefully evaluate both frameworks and consider factors such as performance, scalability, development time, and cost before making a decision.

    Bonus: Some of the best starter templates for both framework

    1. React Native Starter Kit: A comprehensive starter kit that includes multiple features and screens, providing a good starting point for building a React Native app.
    2. react-native-firebase-starter: A starter template that integrates with Firebase for authentication, real-time database, and storage.
    3. React Native Redux Boilerplate: A starter kit that integrates Redux, a popular state management library, and provides a solid foundation for building scalable React Native apps.

    For Flutter:

    1. Flutter Starter Kit: A comprehensive starter kit with many features and screens, providing a good starting point for building a Flutter app.
    2. Flutter Firebase Starter: A starter kit that integrates with Firebase for authentication, real-time database, and storage
  • React Hooks explained

    React Hooks explained

    What are react hooks?

    Hooks are functions that allow developers to “hook into” React state and lifecycle features from functional components. They are called inside a function component to add React features to it.

    React Hooks are a feature introduced in React 16.8 that allow developers to use state and other React features in functional components. Prior to the introduction of Hooks, it was necessary to use class-based components to use state and other React features in a React application.

    Hooks are functions that allow developers to “hook into” React state and lifecycle features from functional components. They are called inside a function component to add React features to it. By using Hooks, developers can use state and other React features without writing a class component.

    There are several built-in Hooks that are provided by React, such as useState and useEffect.

    useState is a Hook that allows a functional component to have state. It takes an initial state as an argument and returns an array with two elements: the current state and a setter function that can be used to update the state. An example :

    import React, { useState } from 'react';
    
    function Example() {
      const [count, setCount] = useState(0);
    
      return (
        <div>
          <p>You clicked {count} times</p>
          <button onClick={() => setCount(count + 1)}>
            Click me
          </button>
        </div>
      );
    }
    
    

    useEffect is a Hook that allows a functional component to perform side effects. It takes a function as an argument and is called after the component renders. The function passed to useEffect will be called whenever the component is updated, similar to the componentDidUpdate lifecycle method in a class-based component. Here’s an example of how useEffect can be used to fetch data and update the state of a functional component:

    import React, { useState, useEffect } from 'react';
    
    function Example() {
      const [data, setData] = useState(null);
    
      useEffect(() => {
        fetch('https://www.expiredqueues.com/api/endpoint')
          .then(response => response.json())
          .then(data => setData(data));
      }, []);
    
      return (
        <div>
          {data ? <p>{data.message}</p> : <p>Loading...</p>}
        </div>
      );
    }
    

    Hooks provide a way to add state and other React features to functional components and can help make code easier to understand and maintain by reducing the need to use class-based components.

    So what are custom hooks?

    Custom React Hooks are functions that allow developers to extract reusable logic from components and share it across multiple components. They are a way to share behavior that can be defined using React Hooks, such as useState and useEffect, between multiple components.

    Custom React Hooks are created by defining a function that starts with the word “use” and performs some logic using one or more of the built-in Hooks provided by React. Let’s write an example of a simple custom hook that fetches data from an API and returns the data and a loading status:

    import { useState, useEffect } from 'react'
    
    function useFetchData(url) {
      const [data, setData] = useState(null)
      const [loading, setLoading] = useState(true)
    
      useEffect(() => {
        async function fetchData() {
          const response = await fetch(url)
          const data = await response.json()
          setData(data)
          setLoading(false)
        }
        fetchData()
      }, [url])
    
      return { data, loading }
    }
    
    

    This custom hook can be used in a component like this:

    import { useFetchData } from './useFetchData'
    
    function Example() {
      const { data, loading } = useFetchData('https://www.expiredqueues.com/api/data')
    
      if (loading) {
        return <p>Loading...</p>
      }
    
      return (
        <ul>
          {data.map(item => (
            <li key={item.id}>{item.name}</li>
          ))}
        </ul>
      )
    }
    
    

    In this example, the useFetchData custom hook is called inside the Example component to fetch data from an API and store the data and loading status in state. The hook returns an object with two properties: data and loading, which are destructured and used in the component to display the data or a loader component while the data is being fetched.

    Custom React Hooks can make it easier to reuse logic across multiple components and can help to make code more modular and maintainable. They can also make it easier to test and debug code, as the logic can be separated into individual functions that can be tested in isolation.

  • Git commands I wish I knew early

    Git commands I wish I knew early

    It has been a little more than a decade since I started coding.

    Started career in this industry as a web designer, then moved on to become front-end developer with savvy HTML and CSS tricks. Later around 2012 started renaming all resume and online profiles to claim to be JavaScript developer – with Vanilla JS, AngularJS blah.. blah.. blah… and then now a full-stack developer. Heck!!!

    One simple thing has remained consistent even though I have moved on from position to position, shifting focus from design to programming, changing primary language from Photoshop to PHP to JavaScript – is the tools I use to work.

    Git and Github, in particular, has played a major role in the career. Along with its useful features – it brought many nightmares as well.

    Committing passwords, secret keys, unwanted changes etc. – I have had my fair share of embarrassments! I wish I knew more than `git push` and `git pull`.

    Git commands I wish I knew early

    1. Ignore changes from tracked files, temporarily
    2. Undo local changes
    3. Remove file from remote Git repository but keep locally
    4. Remove git tracking entirely from a project

    1. Temporarily ignore changes from tracked files

    Tell Git to stop tracking changes

    git update-index --assume-unchanged filename.ext 

    and to start tracking again –

    git update-index --no-assume-unchanged filename.ext 

    2. Undo All Local Changes

    Please note the dot, meaning reset everything to last pull state in the current directory.

     git checkout . 

    If you just wish to reset one file, replace the dot with filename.ext

    3. Remove file from remote Git repository but keep locally

    You join the project in the sometimes in the middle of dev activities. The File is already on the remote repository – let us say ‘.env’ or my ‘secret.keys’.

    Following command to rescue:

    git rm --cached filename.ext 

    Or if you have to remove an entire directory, .e.g. `fakedata/` then:

    git rm --cached -r directoryName 

    Above, “-r” means, recursively. 

    4. Remove git tracking entirely from a project

    Let’s say you cloned a git repo, some boilerplate or starter template but it has all the tracking pointed towards its author git repository.

    When you need to start fresh and remove the old git tracking and initialize new git repo, do following:

    rm -rf .git

    Example above, “-rf” means recursively force the command. Git stores all tracking data inside hidden “.git” directory. All we did here is deleted that directory.

    Now if you wish to start fresh git repo on this same directory – “git init” should do.

    Tips

    Take a look on StackOverflow for top voted questions.

    https://stackoverflow.com/questions/tagged/git?sort=votes&pageSize=15

  • How to set Cookies to share across all subdomains using JavaScript

    Browser Cookies, is a very handy feature that enables us as a web developer to do so many interactive programming. Recently since HTML5 raised up, its Web Storage is replacing this feature. But there is one area where Web Storage fails to achieve the result – subdomain access. There we have to again jump back for old school document.cookie method.

    In this very quick tutorial, lets discuss how we can setup browser cookies that can be accessed from all subdomains and root domain. But proceeding further requires basic knowledge of cookies, and if you need to learn, Tutorial Point has good article on JavaScript Cookies.

    Steps:

    1. Prepare the cookie name/value
    2. Get the top level domain and assign as .domain.com
    3. Set the path to root path=/
    4. Set Expires (optional)

    Lets set up a example cookie. Example take as ‘Last time report generated’ to showup across subdomains.

    
    //variables
    var LastReportGenerated="Jul 11 2013",
    baseDomain = '.expiredqueues.com',
    expireAfter = new Date();
    
    //setting up  cookie expire date after a week
    expireAfter.setDate(expireAfter.getDate() + 7);
    
    //now setup cookie
    document.cookie="Report={'ReportName':'MainReport', 'lastGenerated':" + LastReportGenerated + "}; domain=" + baseDomain + "; expires=" + expireAfter + "; path=/";
    
    

    Major thing to take care here is:

    Your domain must be in format of “.domain.com” – dot and root domain and your path=/ always. If you don’t setup your path=/, auto path will be saved as from where the cookies is being saved hence it wont be accessible across any subdomain.

    You can try copy paste code above in the Console, and see the result in Resource Panel. If you happen to successfully run the script above, you will get a preview:

    JavaScript Cookie

    Now that ‘Report’ cookie should be available across all subdomains like = main.cssjunction.com, tuts.cssjunction.com etc.

    You might be interested in:

  • How to remove black border around input buttons in IE 7?

    Here I am sharing a bullet proof working solution to remove ugly black border around IE 7 input buttons.

    Problem

    The problem is there when a submit button is inside the form element. Click outside the form, form focus is gone,thus black border is gone. But form is focused when page loads so the problem exists there.

    IE7 Black border around input buttons

    Not working solution

    Every one suggest to add outline:none to fix this problem, since outline property is not supported by IE7, I say that this is a not working solution.

    Bullet proof Solution

    Just one property is required to get rid of this black border. Open you reset css file and add the these lines:

    input[type=submit],
    input[type=reset],
    input[type=button]
    {
           filter:chroma(color=#000000);
    }
    

    Why in reset css file?

    Because the problem is for all buttons in IE 7, since adding this fix in reset.css will fix our problem in entire site.

    That’s it. All black border is gone now. The fix is tried/tested against IE 7.

    Result

    Fixed IE7 Black border around input buttons

    Better if you put this fix in IE7-CSS file.

    Similar IE 7 Quick Trick

    How that sound to you? Isn’t it helpful :).
  • Fresh Pixels for Your Inspiration

    Recently I was browser some best galleries for inspiration on my upcoming project, & I found a lot of things new & very much inspired me.

    Those carefully crafted pixels here I want to share with you. Really these pixels are awesome. Have a look at below.

    Fresh Pixels for Your Inspiraion. (more…)

  • Resize rounded rectangle in Photoshop

    Aesthetic interfaces isn’t a easy work. Most designers are working with Photoshop to achieve their best. Rounded corners rectangles are one of the most widely used techniques in interfaces design. While designing in Photoshop, we have Shape tool (U) which gives us easy option to create rounded rectangles. But most designer suffers from hell when they try to resize these kinds of rounded rectangles. (more…)

  • Create Tooltip using jQuery

    Create Tooltip using jQuery

    Tooltips are visually appealing, very user friendly way to notify users. Today we are going to make a tooltip using jQuery that you can use it anywhere in your webpage.
    While creating this tooltip, this is assumed that you are familier with html CSS. You need to know these techniques to understand the development.

    Pre-requirement

    For creating a visually appealing tooltip, we need following assets ready, (more…)