forked from vasanthk/react-bits
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Spreading props on DOM elements | ||
* When we spread props we run into the risk of adding unknown HTML attributes, which is a bad practice. | ||
* | ||
* | ||
* @Reference: | ||
* React Design Patterns and best practices by Michele Bertoli | ||
*/ | ||
|
||
// BAD | ||
// This will try to add the unknown HTML attribute `flag` to the DOM element | ||
|
||
const Sample = () => (<Spread flag={true} className="content"/>); | ||
const Spread = (props) => (<div {...props}>Test</div>); | ||
|
||
// GOOD | ||
// By creating props specifically for DOM attribute, we can safely spread. | ||
const Sample = () => (<Spread flag={true} domProps={{className: "content"}}/>); | ||
const Spread = (props) => (<div {...props.domProps}>Test</div>); |