Skip to content

Conversation

@pavyarov
Copy link

@pavyarov pavyarov commented Apr 4, 2019

Added stringify boolean attributes, because it causes Warning at console.

Btw standard React behavior is just omit non-standard boolean attributes. Maybe better way is omit boolean values?

image

DOM Attributes in React 16

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 95.851% when pulling 21d1cd6 on pavyarov:master into 30e1d59 on redneckz:master.

@@ -0,0 +1,13 @@
// @flow

const BOOLEAN_DOM_ATTRIBUTES = ['checked', 'selected', 'disabled', 'readonly', 'multiple', 'ismap'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Деградация к React 15.
Лучше идти от attrs.


const BOOLEAN_DOM_ATTRIBUTES = ['checked', 'selected', 'disabled', 'readonly', 'multiple', 'ismap'];

export function stringifyBooleanProps(obj?: {} = {}): { [string]: mixed } {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужна сериализация в строку как для булевых так и для других типов атрибутов

return Object.entries(obj).reduce(
(acc, [key, value]) =>
(typeof obj[key] === 'boolean' && !BOOLEAN_DOM_ATTRIBUTES.includes(key)
? { ...acc, [key]: String(value) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для false в новой спеке лучше вообще выбрасывать ключ

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

Successfully merging this pull request may close these issues.

3 participants