我正在尝试使用组件接收的道具使用React hook setState()设置状态。我尝试使用以下代码:
import React,{useState , useEffect} from 'react';
const Persons = (props) => {
// console.log(props.name);
const [nameState , setNameState] = useState(props)
console.log(nameState.name);
console.log(props.name);
return (
<div>
<p>My name is {props.name} and my age is {props.age}</p>
<p>My profession is {props.profession}</p>
</div>
)
}
export default Persons;
Run Code Online (Sandbox Code Playgroud)
问题是加载组件时正在设置状态。但是,当它收到新的道具时,状态不会更新。在这种情况下如何更新状态?提前致谢。
我们有一个应用程序,其中Excel文件中的数据(存在于共享路径中)移动到数据库.如果有任何错误,文件将通过在日志文件中写入错误来移动到错误文件夹.它使用Windows服务进行操作.
有时文件没有任何错误仍然通过写入日志移动到错误文件夹External table is not in the expected format.但是同一文件再次上传一次或多次,它移动到数据库没有任何错误.
Windows服务,DB和共享路径都存在于XP Server中.这些年来应用程序运行良好.但是在最近几天,几乎每个文件都出现了上述问题.
我们也安装了Microsoft 2003,2007,2012办公组件和访问引擎.但问题仍然存在.
我在提到下面的Windows服务代码.请帮忙.提前致谢.
using System.IO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Common;
namespace Impexp_Service
{
public partial class Service1 : ServiceBase
{
System.Timers.Timer T1 = new System.Timers.Timer();
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
///start
///
{
SqlConnection strconnection = new SqlConnection();
strconnection.ConnectionString = @"Data Source=XXXXXX;Initial Catalog=XXXX;User ID=XX;Password=XXXXXX;"; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Twilio Flex WebChat 发送和接收消息。我需要在发送消息之前修改消息。因此,我添加了一个侦听器beforeSendMessage,在componentDidMount()其中收集消息正文、转换消息并发送消息。这里的问题是它同时发送原始消息和转换后的消息。我的目标是单独发送转换后的消息。你能帮我一下吗?谢谢。
componentDidMount() {
FlexWebChat.Actions.addListener(
'beforeSendMessage',
async (payload) => {
const { body, channelSid } = payload;
const modifiedBody = transform(body) //Transforming the message here
await FlexWebChat.Actions.invokeAction('SendMessage', {
body: modifiedBody, // Sending the transformed message
channelSid,
})
}
)
}
Run Code Online (Sandbox Code Playgroud) 我们可以通过使用来尝试获得最大年龄
SELECT TOP 1 age FROM Head1 ORDER BY Age DESC
Run Code Online (Sandbox Code Playgroud)
但我尝试在SQL Server中使用while循环
码
declare @a int, @m int, @maxo int;
set @maxo = 0;
while(@a<10)
begin
select name, @m = age from head1 where ID = @a;
if @m>@maxo
@maxo = @m;
set @a=@a+1;
end
print @maxo
Run Code Online (Sandbox Code Playgroud)
错误
消息141,级别15,状态1,行5
为变量赋值的SELECT语句不能与数据检索操作组合.消息102,级别15,状态1,行7
'@maxo'附近的语法不正确.
我有点被困在这里.请帮帮人......
我正在尝试使用AXIOS从Rest API获取数据,如下所示:
require('dotenv').config();
const axios = require('axios');
var url = 'https://931eb067-05c0-492a-8129-48ebfc27d426-bluemix.cloudant.com/dummy/_design/NEW_VIEW_DESIGN/_view/new-view?include_docs=true';
axios.get({url,auth: {
username: process.env.account,
password: process.env.password
}}).then((res)=>{console.log(res.data);})
.catch((e)=>{console.log(e)});
Run Code Online (Sandbox Code Playgroud)
我可以通过提供凭据来单独访问提及的URL,但是在使用AXIOS时出现以下错误
“ url”参数必须为字符串类型。在Url.parse处收到的类型对象
出了什么问题?
我打算使用 react-router 在 React 中设置活动路由的样式。我正在使用 NavLink 这样做。请看下面的代码:
组件.JS
import React from 'react';
import classes from './navBar.module.css';
import {NavLink} from 'react-router-dom'
const NavBar = (props) => {
return (
<div className={classes.navBarStyle}>
<p className={classes.navBarTitle}>EMPOYEE DATABASE</p>
<nav className={classes.nav}>
<ul className = {classes.navUl}>
<li><NavLink to="/" exact>HOME</NavLink></li>
<li><NavLink to="/addEmployee">ADD</NavLink></li>
</ul>
</nav>
</div>
)
}
export default NavBar;
Run Code Online (Sandbox Code Playgroud)
组件.module.css
.nav {
height: 100%;
}
.navUl {
list-style-type: none;
margin: 0;
padding: 0;
height: 100%;
display: flex;
}
.navUl li {
height: 100%;
}
.navUl li a{ …Run Code Online (Sandbox Code Playgroud) 我试图使用Filewatcher检测文件夹中的文件,并将文件移动到新位置.使用控制台应用程序这样做时,我收到错误The process cannot access the file because it is being used by another process.
我File.Move(f.FullName, System.IO.Path.Combine(@"C:\Users\ADMIN\Downloads\FW_Dest", Path.GetFileName(f.FullName)));在OnChanged方法中遇到此错误.请检查以下代码并帮助我解决此问题.提前致谢.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.Permissions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Run();
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\Users\ADMIN\Downloads\FW_Source";
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "*.*";
watcher.Created …Run Code Online (Sandbox Code Playgroud) c# ×2
reactjs ×2
sql-server ×2
.net ×1
axios ×1
cloudant ×1
css ×1
database ×1
excel ×1
file-watcher ×1
node.js ×1
react-hooks ×1
sql ×1
twilio ×1
twilio-flex ×1