pomber / didact

A DIY guide to build your own React
https://pomb.us/build-your-own-react/
6.29k stars 531 forks source link

Add style prop #14

Closed gvergnaud closed 10 months ago

gvergnaud commented 4 years ago

Hi!

Here is the implementation for the style object prop.

Thanks again for your work on Didact :)

harryheman commented 2 years ago

Another solution:

Object.keys(nextProps)
    .filter(isProperty)
    .filter(wasAdded(prevProps, nextProps))
    .forEach((key) => {
      if (key === 'style' && typeof nextProps[key] === 'object') {
        Object.assign(node.style, nextProps[key])
      } else {
        node[key] = nextProps[key]
      }
    })