Coder Social home page Coder Social logo

Comments (2)

skyrpex avatar skyrpex commented on July 19, 2024

Just in case you didn't know, you can rename them while destructuring:

const { for: htmlFor, class: classNames } = {
    for() {},
    class() {},
};

from babel-plugin-jsx.

oliverfindl avatar oliverfindl commented on July 19, 2024

Hello,

sure I am familiar with object deconstructing syntax. But my main issue is, that I have library, which is already outputting JSX template (using className instead of class) and wanted to write Vue wrapper for it. If I rename className to just class there, it would break in React instead. My current JSX template implementation in that library looks like this (simplified):

class Library {

	constructor(options) {
		// ...
	}
	
	// ...

	get attributes() {
		// ...
		return {
			// ...
		};
	}
	
	// ...

	get template() {
		const { attributes } = this;
		return <div ...attributes>...</div>;
	}

}

Note that this is not in Vue (or React) component, but it is only getter from my library, that should be used in Vue/React component as template. Basic usage in Vue/React would be as instance (which is reactive) and each mutation of its state would change my JSX template output that would be directly mapped into component.

Sure I can copy whole template getter from my library to Vue component and use it like this:

// ...
render() {
	const { attributes } = this;
	if(attributes.className) {
		attributes.class = attributes.className;
		delete attributes.className;
	}
	return <div ...attributes>...</div>;
}
// ...

But then I would have to manage separate template just for Vue, which I wanted to avoid in first place. At this point, it would be more straightforward to use standard Vue template syntax instead of JSX.

It would be nice, if this plugin could transform className into class (and htmlFor into for) attribute at compilation time, otherwise I would suggest to rename it to something else (e.g.: .vjsx), because it is not (fully) compatible with JSX syntax, that React defined first.

Thanks.

from babel-plugin-jsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.