Giter Site home page Giter Site logo

Comments (6)

j-f1 avatar j-f1 commented on May 14, 2024 1

This has a possible security issue: if you pass a user-provided string as the first child of a component without props, the user may be able to misuse your API, allowing them to insert any props theyโ€™d like into the component.

from rfcs.

streamich avatar streamich commented on May 14, 2024

Here is user space solution:

const h = React.createElement;

React.createElement = (type, props, ...children) => {
  if (typeof props !== 'object') {
    children = [props, ...children];
    props = {};
  }

  return h(type, props, ...children);
};

from rfcs.

dantman avatar dantman commented on May 14, 2024

There's a library directly linked to by the React documentation that offers the syntax you're looking for.

https://github.com/mlmorg/react-hyperscript

from rfcs.

PascalPixel avatar PascalPixel commented on May 14, 2024

@streamich Thank you for your code:

  • typeof == 'object' does not distinguish between arrays and objects (both are true)
  • children can be an object as well
  • my own user space solution checks if the first key in the object is $$typeof
  • this is still very crude, could you improve my code?

@dantman hyperscript needs the children to be in an array, createElement doesn't, so using it actually adds a bit more overhead, that's why I'm looking to use createElement itself, or is it easy to turn off arrays in hyperscript somehow?

from rfcs.

dantman avatar dantman commented on May 14, 2024

@Superpencil Seems like a pretty small difference, but it does look like there is an issue on the topic and there is a branch in the repo linked that implements the behaviour you want.

I'd think it would be easier to convince the library to implement the behaviour you want than to get React to change how the API works for a use case that React.createElement isn't intended for.

from rfcs.

PascalPixel avatar PascalPixel commented on May 14, 2024

@dantman you're right, it's a small difference, I'll pursue the issue there, thank you!
@j-f1 Thank you! I was sharing my code in the hope someone would be able to point out some security issue :)

from rfcs.

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.