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

lzy-react

v2.4.3

Published

```tsx import { render } from 'lzy-react'

Downloads

2

Readme

创建组件

import {  render  } from 'lzy-react'

function App() {
  return { 
    template: `<div>App</div>`,
  }
}

export default App

// 在index中使用render方法渲染根组件
render(App, document.getElementById('root'))

使用Hook 绑定事件

import { myUseState,myUseEffect } from 'lzy-react'

function App(){

  // 使用useState
  const [num,setNum] = myUseState(0)

  // myUseEffect可以通过传入不同的参数,当作生命周期钩子进行使用
  myUseEffect(()=>{
    console.log('组件mount阶段时执行')
  },[])
  myUseEffect(()=>{
    console.log('num发生变化时执行')
  },[num])
    myUseEffect(()=>{
    console.log('组件umMount阶段时执行')
  })

  //创建事件 并在data中注册
  function addNum(){
    setNum(num+1)
  }
  

  return {
    data:{  addNum  }, //需要在data里注册事件才能绑定
    template:`<div onClick={ addNum }>App</div>` // 在div中onClick绑定点击事件
  }
}

使用子组件 给子组件传递props

//可以传递函数  实现事件冒泡和下发 (父子组件之间的事件传递)
import Test from './components/Test'

function App(){

  const obj = {a:1,b:2}

  return {
    components:{ Test }, // 在components中注册需要使用的子组件
    data:{ obj }, // 在data里注册需要传递的props才能传递 
    template:`<Test  obj={obj} ></Test>` // 使用大写双标签 并传递props
  }
}

// 在子组件中接收props(单向数据流  子组件修改props会发出警告 )
function Test(props){ ... }

使用map渲染列表(diff开发未完成 暂时不需要传入key)

//注意使用map渲染时需要使用根标签包裹起来
const [arr,setArr] = useState([1,2,3])

return {
  template:
  `<div>
  ${arr.map((index,item)=>{
    return `<div>${item}</div>`
  })}
  </div>`
}

补充说明 使用注意

  1. 只能使用双标签 , 暂时不支持单标签解析
  2. 传递的props和绑定事件需要在data里面注册
  3. 事件暂时仅支持onClick
  4. 暂时不支持行内函数