Skip to content

Example using a custom JSX pragma for enable better tooling for custom elements.

Notifications You must be signed in to change notification settings

domehead100/react-ce-ubigeo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project was bootstrapped with Create React App.

How to test

Just run the app and drop/choose the ubigeo.txt file that is inside public/ folder.

Background

A element, by definition and spec, cannot accept complex properties like objects or arrays. This is a problem when we want to use these kinds of properties in a React project.

For example, this code doesn't work:

const App = function() {
  const data = { a: true }
  return (
    <div className="my-app">
      <my-comp data={data} />
    </div>
  )
}

Because in runtime, the data passed as attribute is converted to string using .toString(). For that reason, if you pass an object, you will ended up receiving an [object Object] (because { a: true }.toString()).

Another problem of using custom elements in JSX is respect to custom events. By default, React don't recognize custom events and never will add the listener to the element.

For example, this code doesn't works:

const App = function() {
  return (
    <div className="my-app">
      <my-comp onMyCustomEvent={console.log} /> // 'my-custom-event'
    </div>
  )
}

You then will ended up using a ref callback to add the listeners manually.


Available Scripts

In the project directory, you can run:

yarn start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

yarn build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.


You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

About

Example using a custom JSX pragma for enable better tooling for custom elements.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published