Skip to content

Commit

Permalink
added react js snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
akmamun committed Jan 9, 2019
1 parent 50533a9 commit 2217e8a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## JavaScript, Python (Flask), Php (Laravel) Code Snippets
## JavaScript, React JS, Python (Flask), Php (Laravel) Code Snippets

## JavaScript Code Snippets
- [JavaScript Form Validation](js/form-validation.js)
- [Select Single Checkbox](js/single-checkbox-selection.js)

## React JS Code Snippets
- [Array Interval Delay and Hide Previous Element](react-js/array-plus-delay.js)
- [Manual Delay](react-js/delay.js)
## Python Code Snippets
- [Create a Host](python/image-cropping.py)
- [Multiple Image Upload](python/multiple-image-upload.py)
Expand Down
23 changes: 23 additions & 0 deletions react-js/array-plus-delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function ArrayPlusDelay(array, delay) {
var i = 0;

// seed first call and store interval (to clear later)

var interval = setInterval(function () {
// each loop, call passed in function
//ReactDOM.render(array[i], document.getElementById("root")=);
if(document.getElementById("id_name") != null) {
document.getElementById("id_name").innerHTML = array[i];
}
// increment, and if we're past array, clear interval
if (i++ >= array.length - 1) clearInterval(interval);
return;
}, delay);

return interval;
}
ArrayPlusDelay(array_numbers, delay_time);

//Example
ArrayPlusDelay([0,1,5,2], 1000); // Every Element Call 1 Second Delay

32 changes: 32 additions & 0 deletions react-js/delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//install prop-types
import React from 'react';
import PropTypes from 'prop-types';

class Delay extends React.Component {

constructor(props) {
super(props);
this.state = {hidden : true};
}

componentDidMount() {
setTimeout(() => {
this.setState({hidden: false});
}, this.props.waitBeforeShow);
}

render() {
return this.state.hidden ? '' : this.props.children;
}
}

Delay.propTypes = {
waitBeforeShow: PropTypes.number.isRequired
};

export default Delay;

// Example Call where want to use it
<Delay waitBeforeShow={1000}> // delay time
{images10}
</Delay>

0 comments on commit 2217e8a

Please sign in to comment.