jsx / JSX

JSX - a faster, safer, easier JavaScript
http://jsx.github.io/
MIT License
1.46k stars 102 forks source link

Proposal for a New JSX Programatic Directive: `<for>` #359

Closed allangomes closed 9 months ago

allangomes commented 10 months ago

I would like to propose the addition of a new JSX directive, <for>, which is inspired by Vue's v-for directive and designed to simplify iteration in JSX. Currently, JSX lacks a straightforward way to achieve looping and iteration similar to Vue's directives, such as v-for and v-if. This proposal aims to improve the developer experience by introducing a new directive for easy iteration in JSX.

Usage Example:

<for (item, key) of items>
  <div>{item.description}</div>
</for>

Transpilation:

The code above could be transpiled to something similar to the following JavaScript code:

items.map((item, key) => (
  <div>{item.description}</div>
))

Benefits:

Implementation Details:

This feature could be implemented by extending the JSX transpiler to recognize the <for> directive and generate the appropriate JavaScript code for iteration. The transpilation process would transform the JSX code into standard JavaScript, maintaining compatibility with the existing JSX ecosystem.

Community Feedback:

I would appreciate feedback from the community and contributors on whether they see value in adding this new directive to JSX. Any suggestions, concerns, or alternative approaches are welcome.

Thank you for considering this proposal. I look forward to discussing the potential inclusion of the <for> directive in JSX.

allangomes commented 10 months ago

the same could work to if, swich, etc.

if

const type = true
return (
  <if condition == "credit">
    // show when credit
  <if-else condition == "debit'>
    // show when debit
  <else>
    // show default
  <if>
)

swich

<swich condition>
  <case "credit">
     // show when credit
  </case>
  <case "debit">
     // show when debit
  </case>
  <default>
     // show default    
  </default>
</swich>
Jacob-Lockwood commented 9 months ago

This repo has nothing to do with the JSX syntax used by React, Solid, etc.

allangomes commented 9 months ago

wow, I think I got confused. Thanks @jacobofbrooklyn!

sarf13 commented 4 days ago

/**

export default function Component() { return (

Portfolio

Hi, I'm John Doe

I'm a full-stack developer with a passion for creating beautiful and functional web applications.

Get in Touch
Hero

About Me

I'm a full-stack developer with over 5 years of experience in the industry. I specialize in building modern, responsive web applications using the latest technologies and best practices.

Skills

  • React
  • Node.js
  • TypeScript
  • SQL

Experience

  • Full-stack Developer, Acme Inc. (2018 - present)
  • Front-end Developer, Widgets Co. (2015 - 2018)
About

My Projects

Check out some of the projects I've worked on.

Project 1

Project 1

A modern web application built with React and Node.js.

Project 2

Project 2

A responsive e-commerce website built with Next.js.

Project 3

Project 3

A mobile-first web application built with React Native.

Get in Touch

Have a project in mind? Let's chat!