Cannot seem to initialize expression value for editing
adamwdotnet opened this issue · 2 comments
Firstly, thanks for creating this package, I love it.
I am having trouble initializing the cronExpression value - even when I provide it a value that it previously provided, the Component always displays "An error occured when generating the expression description. Check the cron expression syntax."
Below is a sample of what I am trying to do:
import React, { useState } from 'react';
import Cron from 'react-cron-generator';
export default function TestPage() {
const [cronExpression, setCronExpression] = useState(null);
const [cronExpressionText, setCronExpressionText] = useState('');
return (<>
<button onClick={()=>{
setCronExpression(null);
}}>Set Null</button>
<input type="text" value={cronExpressionText} onChange={(e)=>setCronExpressionText(e.target.value)} />
<button onClick={()=>{
setCronExpression(cronExpressionText);
}}>Set Value</button>
{cronExpression &&
<Cron
onChange={(e)=> {
console.log(`changed to "${e}"`);
setCronExpression(e);
}}
value={cronExpression}
showResultText={true}
showResultCron={true}
/>
}
</>
);
}
Using the above example, if I type into the text field:
0 0 00 1/1 * ? *
and click set value, the Cron component appears but it displays the error, even though this value was a value provided by the Component.
Any idea how I can get this to work?
@adamwdotnet Thanks for reporting the issue, let me try reproducing the issue.
@adamwdotnet I found a re-render issue when props directly updated the value.
Thanks for using the package and reporting the issue
Please try the latest version of react cron generator [V2.0.10]
Feel free to reopen issue if you are still facing this problem