Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop inside JSX templates has issues #421

Open
Javiani opened this issue Dec 18, 2016 · 1 comment
Open

Loop inside JSX templates has issues #421

Javiani opened this issue Dec 18, 2016 · 1 comment

Comments

@Javiani
Copy link

Javiani commented Dec 18, 2016

I´m using babel to transform JSX templates into virtual-dom hyperscript so I don´t have to write those h() calls manually.

It works well when you don´t have a loop inside of it. Otherwise virtual-dom misses some elements.

return (
		<ul className="list-group">
			{ data.items.map ( (item, index) => {
				return (
					<li className={`list-group-item form-group ${item.edit?'edit':''}`}>
						<div className="item">
							<input type="checkbox" className="check" title={item.id} value={item.id} checked={item.completed} />
							<label title={item.id}>{item.text}</label>
							<button type="button" className="close">
								<span className="remove" title={item.id}>&times;</span>
							</button>
						</div>
						<input type="text" className="form-control" title={item.id} value={item.text} />
					</li>
				)
			})}
		</ul>
	)

This is just a Todo List JSX template, babel´s output seems to be ok, it generates the h() calls just like documentation suggests, but, in the case of the code above, just the checkbox is being created inside div.item. The label, button and even input:text are simply ignored. There´s no error on compilation or even in runtime.

@alejandrofdiaz
Copy link

alejandrofdiaz commented Aug 27, 2018

Anyone has workarounded this?

import { h as hProxy } from 'virtual-dom';
function h(type, props, ...children) {
  return hProxy(type, props, [children]);
}

and use new h instead 🤷

unlight pushed a commit to unlight/webhive that referenced this issue Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants