Skip to content

Commit

Permalink
#56, re render issue on props change, fixed (#57)
Browse files Browse the repository at this point in the history
* codecov

* Resolved render issue on value chsnge from props #56

* Readme changes, version update

* Readme changes, version update
  • Loading branch information
sojinantony01 authored Oct 3, 2023
1 parent 0a338c2 commit e101eeb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
1 change: 0 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
- name: install gh pages separately
run: npm install gh-pages [email protected] [email protected]


- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Simple react component to generate cron expression

Package helps to build linux scheduler cron expression.

[![npm version](https://badge.fury.io/js/react-cron-generator.svg)](https://badge.fury.io/js/react-cron-generator) ![Downloads](https://img.shields.io/npm/dm/react-cron-generator.svg)
<a href="https://github.com/sojinantony01/react-spread-sheet/blob/main/LICENSE">
<img src="https://img.shields.io/npm/l/react-cron-generator.svg" alt="license">
</a>

```
data = '* * * * * * *'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-cron-generator",
"version": "2.0.9",
"version": "2.0.10",
"description": "Simple react component to generate cron expression",
"keywords": [
"React cron generator",
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
<React.StrictMode>
// <React.StrictMode>
<App />
</React.StrictMode>
// </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
Expand Down
18 changes: 6 additions & 12 deletions src/lib/cron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,22 @@ interface State {
const defaultCron = '0 0 00 1/1 * ? *';
const Cron: React.FunctionComponent<CronProp> = (props) => {
const [state, setState] = useState<State>({value:[], headers: loadHeaders(props.options), locale: props.locale ? props.locale : 'en'})
useEffect(()=> {
setValue(props.value ? props.value : "")
if(props.translateFn && !props.locale) {
console.log('Warning !!! locale not set while using translateFn');
}
// if(this.props.onRef) {
// this.props.onRef(this);
// }
}, [])
useEffect(() => {
let newVal = '';
newVal = state.value.toString().replace(/,/g,' ');
newVal = newVal.replace(/!/g, ',');
if(props.value !== newVal) {
setValue(props.value ? props.value : "")
}
if(props.translateFn && !props.locale) {
console.warn('Warning !!! locale not set while using translateFn');
}
}, [props.value])
useEffect(() => {
parentChange(state.value)
state.value && state.value.length && parentChange(state.value)
}, [state.value])
const setValue = (value: string) => {
let prevState = state;
let prevState = {...state};
prevState.value = value.replace(/,/g, '!').split(' ');;
const allHeaders = loadHeaders();
if(value && value.split(' ').length === 6) {
Expand Down Expand Up @@ -100,7 +94,7 @@ const Cron: React.FunctionComponent<CronProp> = (props) => {
}
const getVal = () => {
let val = cronstrue.toString(state.value.toString().replace(/,/g,' ').replace(/!/g, ','), { throwExceptionOnParseError: false, locale: state.locale })
if(val.search('undefined') === -1) {
if(val.search('undefined') === -1 && state.value && state.value.length) {
return val;
}
return '-';
Expand Down

0 comments on commit e101eeb

Please sign in to comment.