{"id":15986024,"url":"https://github.com/coderhs/osk2017-react-js-workshop","last_synced_at":"2025-04-04T21:26:13.906Z","repository":{"id":145141450,"uuid":"111987864","full_name":"coderhs/OSK2017-react-js-workshop","owner":"coderhs","description":"Open Source Kerala 2017 React JS workshop by Jishnu","archived":false,"fork":false,"pushed_at":"2017-11-26T04:31:26.000Z","size":112,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T06:13:03.557Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderhs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-25T08:15:59.000Z","updated_at":"2017-11-25T08:16:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"b3ec8d82-4cad-4061-a7b7-05253cb60891","html_url":"https://github.com/coderhs/OSK2017-react-js-workshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderhs%2FOSK2017-react-js-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderhs%2FOSK2017-react-js-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderhs%2FOSK2017-react-js-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderhs%2FOSK2017-react-js-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderhs","download_url":"https://codeload.github.com/coderhs/OSK2017-react-js-workshop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247250981,"owners_count":20908439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T02:41:55.820Z","updated_at":"2025-04-04T21:26:13.891Z","avatar_url":"https://github.com/coderhs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React JS Workshop by Jishnu\n\n\nDate: 25th November, 2017\nEvent: Open Source Kerala 2017\n\n\n## Create a ToDo app using Vanila JS\n\nCheck `index.html`\n\n## Create a ToDo app using react js.\n\n\n1. `npm install -g create-react-app`\n2. `create-react-app todo-app`\n3. `npm start`\n\nYou will be able to see the default react app at `localhost:3000`.\n\n\nNote:\n\n### ES6 arrow operator (=\u003e)\n\n```js\nvar square = (num) =\u003e { \n    return num * num\n    };\n```\nor if its just a single line\n\n```js\nvar square = (num) =\u003e num * num;\n```\n\n### Import and Export\n\n```js\n// file 1\nexport default function square (num) {\n    return num * num\n}\n\n//file 2\n\nimport square from 'file1.js'\n```\n\nexport multiple items\n\n```js\n// file 1\nexport function square (num) {\n    return num * num\n}\n\nexport function root (num) {\n    return num * num\n}\n\n//file 2\n\nimport {square} from 'file1.js' // to import one method\n\nimport {square, root} from 'file1.js' // to import multiple method\n```\n\n### let\n\n```js\n{\n    let a = 1;\n}\n```\n\n### const\n\n```\n    const a = 1;\n```\n\n### JSX\n\n* Basically like html but it supports variables\n* Makes Life easier\n* Not requried but helps a lot\n* Prevents injection attacks\n\n\nTip: Move items that you think has its own instances to its own file.\n\nCheck file `todo-aopp/hearder.js`\n\n\n### Imports from libraries \u0026 packages\n\n```js\nimport React, { Component } from 'react';\n```\n\nImports local file.\n\n```js\nimport Header from './header';\n```\n\n\n\n`this.setState` is asynchronous\n\n```js\n    if (e.keyCode == 13) {\n        this.setState({\n            value: e.target.value\n        })\n        console.log(this.state.value)\n    }\n```\n\n\n### To access a method in the parent from the child.\n\nIf you require the state of a parent to be changed when an event happens in the child. Then\nwe need to pass in the method reference form the parent to the child as a prop.\n\n```js\n    // parent file\n\n    addTask(task) {\n        let current = this.state.TODOLIST;\n        current.push({\n        id: Date.now(),\n        title: task,\n        completed: false\n        });\n        this.setState({TODOLIST: current})\n    }\n\n    render() {\n        return (\n        \u003cdiv className=\"App\"\u003e\n            \u003cHeader /\u003e\n            \u003cInput addTask = { this.addTask.bind(this) }/\u003e\n        \u003c/div\u003e\n        );\n    }\n\n    // child file\n\n    onKeyDown(e) {\n        if (e.keyCode === 13) {\n            this.setState({\n                value: e.target.value\n            })\n            // we are passing the new value to the add Task props\n            // which is calling the method in the parent.\n            this.props.addTask(e.target.value);\n        }\n    }\n\n    render () {\n        return (\n            \u003cinput placeholder = \"Create new task!\"\n            onKeyDown = {this.onKeyDown.bind(this)} /\u003e\n        )\n    }\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderhs%2Fosk2017-react-js-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderhs%2Fosk2017-react-js-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderhs%2Fosk2017-react-js-workshop/lists"}