Categories
Javascript Learning Tech

React functional child component not re rendering on parent state change?

Hello,

I was also looking answer for similar question.

Here is the quick solution I found and worked for me, hope it helps you too in some scenario we might mistaking

Pitcure (a)

As in the (a) was getting null as a data response in the react child component (where the text shown “Reset linked expired…”) , where actually data was updating from parent component and passed to react child component named <ResetPasswordForm … /> as ‘data’ as a prop, here its full code look like:

function ResetPassword({ }) {
  const router = useRouter();
  const [resetPasswordData, setResetPasswordData] = useState(null);



  useEffect(() => {
   
    const { query } = router;

    if (query && query?.token && query?.email) {
      console.log(query);
      setResetPasswordData({
        ...query
      });
    }
    return () => {
    }
  }, [router]);

  return (<React.Fragment>
    <GlobalCookieContextProvider>
      <div className="app-page" id="appPageEle">
        <Layout>
          <div className={styles.loginFormWrapper}>
            <div className={styles.loginBox}>
              <div className={styles.loginBoxLeft}>
                <LeftBoxImage />
              </div>

              <div className={styles.loginBoxRight}>
                {JSON.stringify(resetPasswordData, 0, 2)}
                <ResetPasswordForm title={'Reset Password'} data={resetPasswordData} />
              </div>
            </div>
          </div>
        </Layout>
      </div>
    </GlobalCookieContextProvider>
  </React.Fragment>);
}

Solution 1 : To fix the issue of null, I have to remove the wrapping GlobalCookieContextProvider component as I was not passing any prop to it and also I have no use in this Reset Password Main component, so after removing the wrapping Provider component it worked like as expected, Boom!.

Results of JSON output attached to the form

Picture (b)

Hence start receiving data from parent react component when state change updated dynamically from URL query params as expected.

But wait, Solution 1, was not working still as expected in certain refreshes, then work around did and moved the all query params check code from nextjs page component to its child level component named ResetPasswordForm component and everything finally working as expected again.

Hope you enjoyed the post, let me know in comments if confused you, will try to re-try to post again.

Happy we learning!

Conclusion

First found the wrapping un-used React Provider component, causing a stop of re-ending of react child component when parent component state update done, but after some further testing its was still breaking, final solution found in moving the router query params check and updating state into the first level child component itself which does the expected checks in useEffect() and render the component fairly with the expected results on query fetch done.

Categories
Learning

Can you help to make me rich?

Would you like to share some ideas or steps i can take become rich or earn good money from good work?

Please drop your comments below.

Will wait to hear from yo all…

Thank you

Categories
Learning

How to calculate the costing of grams from per kg weight?

For the simple question here is the simple answer:

as we know 1kg = 1000 grams

Formular for easy getting grams rate from per kg is looks like:

So g grams is g/1000 kg and the price will be g/1000 * r (rupees/kg)
or
rupees/kg= g*r/1000

For example to calculate the rate of 100 grams from per kg.

Let say we have some wheat item whose rate is 1 kg = 20 rupees and we have to calculate the rate for 100 grams wheat?
100/1000 * 20 = 2 rupees
or
100 * 20/1000 = 2 rupees

Hope this solves our understanings.

Happy learning!

Categories
Learning

If its Laravel or a simple MYSQL a query/fetch of inner join table, return’s id of joined table, but you don’t want that, how to fix?

Hello,

First sorry for such long question in the heading. Will start with small story and then right to the solution fix I found.

Facing issue of getting id of Joined table in my current laravel project, where I need a Id column value from the Main table not the one which I used to inner join for the records to pull in.

Here is my existing query of Laravel returning t he id of customer table where I was looking id of Bill’s Table:

$data = Bill::join('customers', 'customers.id', '=', 'bills.customer_id')
                ->where('bills.store_id', 'LIKE', '%'. $storeId . '%')
                ->orderBy('bills.id', 'desc')
                ->get(['bills.*','customers.*', ]);

So the right solution is at the last line in the above code, please carefully see the get() function array parameters; I switched them, so it finally returns the id values of bills not of customer table. (as customer table also id column which matches with bill’s table column)

$data = Bill::join('customers', 'customers.id', '=', 'bills.customer_id')
                ->where('bills.store_id', 'LIKE', '%'. $storeId . '%')
                ->orderBy('bills.id', 'desc')
                ->get(['customers.*', 'bills.*']);

This results be the records with bills id not customer’s id in laravel elqouent or mysql inner join.

Thanks for reading and learning.

Happy learning.

Categories
Learning

How we can write complex SCSS mixin with if else condition and null value passed or on no value passed?

Hello

Welcome, to this short post on writing/learning a little complex SCSS Mixin for your project/learning.

To keep it straight and short here it is the code example:

@mixin setWH($w: false, $h: false, $unit: false, $isImportant: false) {
   @if $w AND $unit AND $isImportant {
       width: unquote($w + $unit + ' !important');
   } @else if $w AND $isImportant {
       width: $w + ' !important';
   }
   @else if $w AND $unit {
       width: $w + $unit;
   } @else if $w {
       width: $w;
   }
 
   @if $h AND $unit AND $isImportant {
       height: unquote($h + $unit + ' !important');
   } @else if $h AND $isImportant {
       width: unquote($h + ' !important');
   } @else if $h AND $unit {
       height: $h + $unit;
   } @else if $h {
       height: $h;
   }
}

Usage Examples:


//Usage examples:
.myMixinTest1 {
  @include setWH(15, 5, 'em');
}

.myMixinTest2 {
  @include setWH(6, 4.3, "rem");
}

.myMixinTest3 {
  @include setWH(60, false, "px");
}

.myMixinTest4 {
  @include setWH(false, 30, "px");
}

.myMixinTest5 {
  @include setWH(27, 3, "rem", true);
}

It looks complex if you pay a little bit close look, its most simple.

You may extend more with if else or else conditions. I just kept to that extend as not require for me any else condition for error handling or something else to output.

A small ~codepen~ in action!

Hope you like & enjoyed learning!

Happy Learning!

Categories
Learning

Looking for 3D print in Miraroad, Mumbai, Thane?

Hello,

If you are looking for 3D print service and if you got the file and need a print, you can reach out here 3dprint@doableyo.com.

They respond usually on weekends for the delivery of print but you can write them anytime for any queries, they are new in 3D printing 👣🐾 but they can solve and helpful for the problem you might have.

3dprint.doableyo.com (the page will getting ready soon or might got ready)

Thanks for visiting!

Categories
Learning

How to call Laravel one Controller method into another?

Hello welcome to this post!

As of part of learning and development of laravel project I was simply looking syntax how to call laravel controller method in another controller.

Here is some tips and example:

Make sure you declared function as with public keyword while defining any method/function in controller.

Method updateMethod defined in controller called DoctorController.php as follow:

public function updateMethod($request, $id) {
// echo $id;
. . . // more lines of your code here
}

Secondly calling updateMethod in controller called DoctorApiController.php

public function updateDoctor(Request $request, $id) {
      if (Doctor::where('id', $id)->exists()) {
        $result = (new DoctorController)->updateMethod($request, $id);
        
        return response()->json([
            "message" => "Doctor updated successfully"
        ], 200);
        } else {
        return response()->json([
            "message" => "Doctor not found"
        ], 404);
        
    }
   }

If you got any error with DoctorController or your Controller class name not found or any such please add: use App\Http\Controllers\DoctorController; on top of the file.

This was the one way to simply call method of laravel one controller to other.

Hope it helpful. Thanks for visiting and reading.

Categories
Learning

WhatsApp, Facebook, Instagram go down

Hello Hi,

Lot of us facing currently down issue from Whatsapp, Facebook and Instagram:

Here are there tweets on issues:

Instagram

Facebook

Whatsapp

So we don’t need to worry much and relax our nerves and mind and let the giants work on the issue until than we can take some good good nap for living life’s.

Thanks for reading and visiting.

Categories
Learning

Looking for fulltime Sr Frontend Developer position

Hello, welcome here to this post.

Jatinder Singh is looking fulltime Sr Frontend Developer position remotely or at worldwide locaiton.

He have 8+ years of frontend development experience, his core expertise is into ReactJS, NextJs, Angular, NodeJs(30-40%), Javascript, ES6, HTML5, CSS3, Bootstrap, jQuery, GraphQL, ApolloClient and ApolloServer.

His recent work of https://sabziyaan.doableyo.com or https://sz.doableyo.com using NextJS, ReactJS, he have also worked on Ecommerce Project which will be soon launched.

He currently lives in Mumbai with his family.

He actively looking out for fulltime job, in open culture, no politics environment and always seek an opportunity to learn and grow.

He loves the quote of Richard Branson:

To reach out him, you may quickly drop a note at hello@tortoisefeel.com. The message will share instantly with them.

Thank your for reading and visiting the post.

Categories
Learning

What is the syntax or how to add AND with where clause in PHP MYSQL?

Hello, welcome to this short post or an answer for this question.

Here is example do use AND with WHERE clause in MYSQL statement in PHP or general writing of SQL Statement.

SELECT *
FROM orders
WHERE (userId = 111 AND orderId = 185)

This how we can use AND in where clause., similarly if we need OR in WHERE clause, we can use as below:

SELECT *
FROM orders
WHERE (userId = 111 AND orderId = 185)
OR (userId > 100);

Just if we are looking for complex query with multiple OR and AND in OR

SELECT orderId, orderNumber, orderStatus
FROM orders
WHERE (orderId = 185)
OR (orderNumber = 101 AND orderStatus = 'Cancelled')
OR (orderNumber = 102 AND orderStatus = 'InProgress' AND total >=500);

Purpose of this post to give you just syntax you might be looking for, but you know the logic how to implement it and use it!

Thanks for visiting and happy learning!