Skip to content

Commit

Permalink
* Modify createElement as per jsx
Browse files Browse the repository at this point in the history
* Allow unused OwnReact imports
  • Loading branch information
nparashar150 committed Oct 5, 2022
1 parent ec8ac0a commit f4f86dc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
"indent": ["error", 2],
"linebreak-style": 1,
"react/react-in-jsx-scope": "off",
"quotes": ["error", "double"]
"quotes": ["error", "double"],
"no-unused-vars": [
"error",
{
// Allow unused variables that start with OwnReact
"varsIgnorePattern": "OwnReact"
}
]
},
"parserOptions": {
"ecmaVersion": 2021,
Expand Down
5 changes: 3 additions & 2 deletions lib/createElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { styleToString } from "./utils/styleToString";
* @returns {HTMLElement}
*/
export const createElement = (element, props = {}, ...children) => {
// create a new element
const _htmlElement = document?.createElement(element);
// create a new element with the given tagName
let _htmlElement =
typeof element === "string" ? document?.createElement(element) : element();
// add the props to the element
if (props && typeof props === "object" && Object.keys(props).length > 0) {
Object.keys(props)?.map((propName) => {
Expand Down
2 changes: 1 addition & 1 deletion public/js/own-react-bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/components/button/button.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Button = () => {
return <button>Click Me</button>;
import OwnReact from "../../../lib/index";

const Button = (children) => {
return <button>{children}</button>;
};

export default Button;
export default Button;
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import OwnReact from "../lib/index";
// import Button from "./components/button/button";
import Button from "./components/button/button";

const App = () => {
return (
<div id="root2">
<Button>Click me</Button>
<h1>My First Own React App</h1>
{/* <Button /> */}
<p>
<div className="testing">
<h1>My First Own React App with custom Babel and Webpack config</h1>
Expand Down

0 comments on commit f4f86dc

Please sign in to comment.