npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bobliao/use-jquery-hook

v0.1.6

Published

# Why using jquery in react😂?

Downloads

9

Readme

English -英文-

Why using jquery in react😂?

Just for old-expreance using in morden workflow For example:

jQuery Easing

//Can quikely control any elements binded with ref
$(someElemRef.current).show();
$(someElemRef.current).fadeIn();

//The code shows upon is not the point,this is the point:
//Easing Animation:
$({ opacity: 0, bkd: 0 }).animate(
  { opacity: 1, bkd: 2 },
  {
    duration: 200,
    easing: 'easeOutQuart',
    progress: function() {
      $(someElemRef.current).css('opacity', this.opacity);
      $(someElemRef.current).css('backdrop-filter', 'blur(' + this.bkd + 'px)');
    },
    complete: function() {
      $(someElemRef.current).css('opacity', this.opacity);
      $(someElemRef.current).css('backdrop-filter', 'blur(' + this.bkd + 'px)');
    },
  }
);

//Using throw this kind of "last century" code could allows u to do some RELLY quike codeing

In animate() function, I had put easing plugin inside, can using easing functions by animate() straightaway. Easing plugin comes from: https://github.com/gdsmith/jquery.easing Easing plugin usage: https://www.cnblogs.com/yangpeixian/p/10919817.html

jQuery usage

Jquery allows u to do more magic code https://api.jquery.com/

@bobliao/use-jquery-hook

npm install @bobliao/use-jquery-hook

yarn add @bobliao/use-jquery-hook

import useJquery, { jQueryObject, isRunningInServer } from '@bobliao/use-jquery-hook';

(...)
  //Get jquery out of the box
  const $ = useJquery();

  //If you r using TypeScript
  const $:jQueryObject = useJquery();

  (...)
  //If u r using razzle or Next,Could allow you do this to get is the code running in server or client
  if(isRunningInServer){
    //running in server
  }else{
    //running in client
  }
  (...)

(...)

SSR Supported

This hook could run in SSR project without any window undefined ERROR. Even can determine the code is running in server side or client side,throw this:

import useJquery, {
  jQueryObject,
  isRunningInServer,
} from '@bobliao/use-jquery-hook';

if (isRunningInServer) {
  //running in server
} else {
  //running in client
}

===

中文 -Chinese-

为什么在 react 里用 jquery😂?

为了可以节省时间,免得在过于碎片化的代码里飞来飞去费眼费神,有些本来就很简单的事情就用简单的方式来解决就好了。 比如:

Javascript Easing

//可以快速操作绑定了ref的元素(不推荐直接操作($(".xxx"),$("#xxx")),往往容易引起一些混乱,适可而止就好了,不然为什么用react呢?)
$(someElemRef.current).show();
$(someElemRef.current).fadeIn();

//当然非要这么用我也不拦着你,哈哈
$('#container').fadeIn();

//实际上上面的代码还不是目的,下面才是最终目的
//可以快速方便地使用缓动算法,可以缓动任何数值css等,不用把代码拆得七零八落:
$({ opacity: 0, bkd: 0 }).animate(
  { opacity: 1, bkd: 2 },
  {
    duration: 200,
    easing: 'easeOutQuart',
    progress: function() {
      $(someElemRef.current).css('opacity', this.opacity);
      $(someElemRef.current).css('backdrop-filter', 'blur(' + this.bkd + 'px)');
    },
    complete: function() {
      $(someElemRef.current).css('opacity', this.opacity);
      $(someElemRef.current).css('backdrop-filter', 'blur(' + this.bkd + 'px)');
    },
  }
);

//通过上面这种“老掉牙”的方式,可以快速编写一些动画效果。

笔者已经将 Easing 插件内置在了这个钩子里,可以直接通过animat()函数使用 Easing。 Easing 插件来源: https://github.com/gdsmith/jquery.easing 使用方法参考: https://www.cnblogs.com/yangpeixian/p/10919817.html

jQuery 使用方法

jQuery 还是有可取之处的,不了解的可以了解一下。 https://api.jquery.com/

@bobliao/use-jquery-hook

npm install @bobliao/use-jquery-hook

yarn add @bobliao/use-jquery-hook

import useJquery, { jQueryObject, isRunningInServer } from '@bobliao/use-jquery-hook';

(...)
  //从钩子里取出jquery
  const $ = useJquery();

  //如果你用了TypeScript可以指定这个类型
  const $:jQueryObject = useJquery();

  (...)
  //如果在使用SSR,可以通过这个被导出的变脸判断当前代码是运行在服务器端还是运行在客户端
  if(isRunningInServer){
    //如果运行在服务器端
  }else{
    //如果运行在客户端
  }
  (...)

(...)

支持 SSR 运行环境

这个钩子支持 SSR 运行环境,无论您的项目使用的是 Razzle 或者 Next 都不会被window undefined ERROR困扰. 您甚至可以通过这种方式判断当前代码运行在哪个环境下以避免一些 dom 或 bom 操作错误:

import useJquery, {
  jQueryObject,
  isRunningInServer,
} from '@bobliao/use-jquery-hook';

if (isRunningInServer) {
  //如果运行在服务器端
} else {
  //如果运行在客户端
}